簡體   English   中英

為什么GridView中存在於Updatepanel中的LinkBut​​ton沒有觸發OnClientClick事件?

[英]Why LinkButton inside GridView which is present in Updatepanel not firing OnClientClick event?


我將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);

有人可以幫助我解決這個問題。

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

請在鏈接按鈕的OnClientClick上使用它

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM