2014-09-12 93 views
0

我試圖顯示帶有用戶確認消息的AJAX彈出窗口,但是當用戶點擊按鈕時會自動轉到按鈕點擊事件而不顯示消息。 這是我有:ModalPopupExtender沒有在ASP.NET gridview image按鈕中觸發點擊

<asp:GridView ID="GridView1" OnRowCommand="GridView1_RowCommand"> 
    <Columns> 
     <asp:TemplateField ItemStyle-HorizontalAlign="Center"> 
     <ItemTemplate> 
      <asp:ImageButton ID="imgButton1" RowIndex='<%# Eval("PostingID") %>' CommandName="Archive" CommandArgument='<%# Eval("PostingID") %>' runat="server" ImageUrl="/images/a.png" /> 
      <asp:Panel ID="pnlConfirm" runat="server" CssClass="modalPanel" Style="display: none; height:160px; border-color:#B6B6B4;"> 
       <div> 
        <table class="featrEmpDivLoginPopup" style="height:160px; width:460px;" cellspacing="0" cellpadding="0"> 
        <tr> 
         <td id="divClose" runat="server" class="topimglhs533 hedding1" style="height:30px; background-color:#d3d8d2;"> 
          Message 
         </td> 
        </tr> 
        <tr> 
         <td> 
          <div id="jsAlert1_popupBody" style="position: absolute; font-family: Verdana,Arial; font-size: 9pt; padding: 2px; text-align: left; background-color: rgb(255, 255, 255); color: black; top: 34px; width: 450px; left: 1px;"> 
           <div style="padding-top:20px; padding-bottom:5px; text-align:center;">Are you sure you want to Archive this posting?<br></div> 
          </div> 
         </td> 
        </tr> 
        <tr> 
         <td style="width:100px; margin-top:5px; text-align:center;"> 
          <asp:ImageButton ID="btnUpdate" CommandName="Archive" ImageUrl="~/Images/btnarchive.jpg" runat="server" /> 
          <asp:ImageButton ID="btnCancel" ImageUrl="~/Images/cancel2.jpg" runat="server" /> 
         </td> 
        </tr> 
        </table> 
       </div> 
      </asp:Panel> 
      <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="imgButton1" PopupControlID="pnlConfirm" 
       CancelControlID="btnCancel" BackgroundCssClass="modalBg" DropShadow="false"></ajaxToolkit:ModalPopupExtender> 
      <!-- PANEL --> 
     </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

所以我期待在彈出被所示,當用戶會點擊imgButton1而是它關係到事件背後的代碼的時候了。

你們在這段代碼中看到什麼錯誤嗎?

由於提前,Laziale

說明補充說,9月14日:

在Firebug中,我能夠在的ScriptResource.axd看到這兩個錯誤:

enter image description here

燦那與我有的問題有關?

更好的圖片說:

enter image description here

+0

是否加入'的OnClientClick =「返回false;'的'的ImageButton(imgButton1)」幫助 – 2014-09-12 16:26:18

+0

@DennisR沒有回發發生,但還沒有顯示以及彈出感謝 – Laziale 2014-09-12 16:59:21

+0

您能不能告訴我們一些CS代碼的imagebutton點擊事件? – 2014-09-21 04:38:08

回答

0

問題是,我並沒有用的UpdatePanel的ContentTemplate的頁面。一旦我確實把問題解決了,問題就解決了。感謝所有的答案。

0

我想下面的「imgButton1」在邊網格,以便沒有辦法到ModalPopupExtender得到「imgButton1」。

,如果你喜歡做 1.添加ModalPopupExtender用假目標,您可以執行以下步驟控制

<ajax:ModalPopupExtender ID="lnkEditPopup" TargetControlID="hfo" DropShadow="true" 
    BackgroundCssClass="modalBackground" PopupControlID="pAddEditApprover" runat="server"> 
</ajax:ModalPopupExtender> 

<%-- START : Fake Controler for ModalPopupExtender --%> 
<asp:HiddenField ID="hfo" runat="server" /> 
<%-- END : Fake Controler for ModalPopupExtender --%> 
  • 在網格視圖

    使用項目的命令

    <asp:GridView ID="gv" runat="server"OnSelectedIndexChanging="gv_SelectedIndexChanging"> 
        <Columns> 
        <asp:CommandField 
    SelectImageUrl="~/Styles/images/info-group.png" 
    ButtonType="Image" 
    ShowSelectButton="true" 
    AccessibleHeaderText="Edit" /> ... // rest of grid data 
    
  • 3 .cs文件

    protected void gridApprover_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) 
    { 
        lnkEditPopup.Show(); 
        } 
    

    試試這個它爲我工作

    0

    我認爲問題是當你點擊圖像按鈕事件不火所以要解決這個問題,我想你應該叫從圖像按鈕事件彈出擴展。

    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" CancelControlID="btnCancel" 
        TargetControlID="FakeHiddenField" PopupControlID="Panel4" PopupDragHandleControlID="PopupHeader" 
        Drag="true" BackgroundCssClass="ModalPopupBG"> 
    </asp:ModalPopupExtender> 
    

    然後去圖像按鈕事件(方法)在的.cs寫這段代碼有

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e) 
        { 
    
         this.ModalPopupExtender1.Show(); 
        } 
    

    試試這個這個,它會爲你

    0

    工作,如果你只是想有一個確認,如果他想存檔這張貼,爲什麼你不使用JavaScript?

    OnClientClick="if (!confirm('Are you sure you want delete?')) return false;" 
    

    這使JavaScript提醒有機會檢查用戶想要什麼。

    <asp:ImageButton ID="imgButton1" RowIndex='<%# Eval("PostingID") %>' OnClientClick="if (!confirm('Are you sure you want delete?')) return false;" CommandName="Archive" CommandArgument='<%# Eval("PostingID") %>' runat="server" ImageUrl="/images/a.png" /> 
    
    0

    我建議,這個問題是imgButton1pnlConfirmModalPopupExtender1住行內你GridView。 A GridView考慮到它將有多行。這意味着您不能通過各自的ID直接引用控件。

    這裏的東西你可以做也可以使用:

    • 創建從DataControlField繼承的控制 - 可以將其添加到您的行...
    • 控制的內部創建一個ImageButton
    • 爲imagebutton添加消息到OnClientClick事件。
    • 在任何GridView中使用您的新控件。

    一些示例代碼在這裏:

    public class GridDeleteButton : DataControlField, IDisposable 
    { 
        private ImageButton button; 
        public event ImageClickEventHandler Click; 
    
        public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex) 
        { 
         button = new ImageButton 
           { 
            ImageUrl = "...", 
            CommandName = "Delete", 
            OnClientClick = @"return confirm('Are you sure?');" 
           }; 
    
         if (Click != null) button.Click += Click; 
    
         cell.Controls.Add(button); 
        } 
    
        protected override DataControlField CreateField() 
        { 
        } 
    
        public void Dispose() 
        { 
         if (button != null) button.Dispose(); 
        } 
    }