为什么UpdatePanel中存在的GridView内的LinkBut​​ton不会触发OnClientClick事件?

时间:2015-05-18 11:10:40

标签: c# asp.net gridview updatepanel asplinkbutton


我已经将我的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应在用户点击时显示确认消息框。但它没有显示出来。
我尝试从后面的代码注册Asynchronous PostBack事件,如下所示:

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

请有人帮我解决这个问题。

2 个答案:

答案 0 :(得分:0)

使用 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>

答案 1 :(得分:0)

请在链接按钮的OnClientClick

上使用此功能
 OnClientClick='return confirm("Are you sure you want to Delete this?");return false;'