【问题标题】:Why LinkButton inside GridView which is present in Updatepanel not firing OnClientClick event?为什么 Updatepanel 中存在的 GridView 内的 LinkBut​​ton 不触发 OnClientClick 事件?
【发布时间】:2015-05-18 11:10:39
【问题描述】:


我已将 GridView 放置在 Updatepanel 中,并在那里定义了几个带有一个 LinkBut​​ton 的列。但是对于那个 LinkBut​​ton OnClientClick 事件没有触发。相反,它正在回发。
以下是代码:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
   <ContentTemplate>
      <asp:GridView ID="gvUnmappedICD" runat="server" EmptyDataText="No Records are added yet."
             OnRowCommand="gvUnmappedICD_RowCommand" OnRowDataBound="gvUnmappedICD_RowDataBound">
          <Columns>
             <asp:TemplateField HeaderText="Action">
                 <ItemTemplate>
                    <asp:LinkButton ID="lnkRemove" runat="server" CommandArgument='<%#Eval("KEYWORD") %>' CommandName="remove" ClientIDMode="AutoID"
                        OnDataBinding="lnkRemove_DataBinding" OnClientClick='return confirm("Are you sure you want to Delete this?");' ToolTip="Click to Remove this record." Text="Remove" />
                 </ItemTemplate>
          </Columns>
      </asp:GridView>
   </ContentTemplate>
</asp:UpdatePanel>

这个 ID 为 lnkRemove 的 LinkBut​​ton 应该在用户点击它时显示一个确认消息框。但它没有显示出来。
我已经尝试从后面的代码中注册异步 PostBack 事件,如下所示:

ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lbRemove);

请任何人帮助我解决这个问题。

【问题讨论】:

    标签: c# asp.net gridview updatepanel asplinkbutton


    【解决方案1】:

    使用 PostBackTrigger

    <asp:ScriptManager ID="scriptManager" runat="server">
            <asp:UpdatePanel ID="updatePanel" runat="server">
                <asp:GridView ID="gvUnmappedICD" runat="server" EmptyDataText="No Records are added yet."
             OnRowCommand="gvUnmappedICD_RowCommand" OnRowDataBound="gvUnmappedICD_RowDataBound">
          <Columns>
             <asp:TemplateField HeaderText="Action">
                 <ItemTemplate>
                    <asp:LinkButton ID="lnkRemove" runat="server" CommandArgument='<%#Eval("KEYWORD") %>' CommandName="remove" ClientIDMode="AutoID"
                        OnDataBinding="lnkRemove_DataBinding" OnClientClick='return confirm("Are you sure you want to Delete this?");' ToolTip="Click to Remove this record." Text="Remove" />
                 </ItemTemplate>
          </Columns>
      </asp:GridView>
                <Triggers>
                    <asp:PostBackTrigger ControlID="lnkRemove" />
                </Triggers>
           </asp:UpdatePanel>
    

    【讨论】:

    • 嗨@vakeel,您的回答将导致以下错误。 A control with ID 'lnkRemove' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
    【解决方案2】:

    请在链接按钮的OnClientClick上使用它

     OnClientClick='return confirm("Are you sure you want to Delete this?");return false;'
    

    【讨论】:

      猜你喜欢
      • 2011-06-19
      • 2019-07-23
      • 2011-09-10
      • 2011-01-12
      • 2017-09-03
      • 1970-01-01
      • 1970-01-01
      • 2013-07-02
      • 1970-01-01
      相关资源
      最近更新 更多