2012-12-07 59 views
6

我有按鈕單擊事件不點火,但是modalpopupextender在我的項目工作

<asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" /> 

enter code here
聯繫 - *如果Neccesery

 <asp:ModalPopupExtender ID="ModalPopupExtender1" PopupControlID="Panel1" TargetControlID="btnAdd" 
      BackgroundCssClass="modalBackground" runat="server"> 
     </asp:ModalPopupExtender> 
     <asp:Panel ID="Panel1" align="center" CssClass="modalPopup" runat="server"> 
     <div class="body-reg-left"> 
     <div class="body-top-reg"> 
      <div class="he-reg"> 
       <b>Admin </b>- *If Neccesery</div> 
     </div> 
      <table> 
       <tr> 
        <td> 
         <asp:Label ID="lblCategoryID" runat="server" Text="" CssClass="lbF"></asp:Label> 
        </td> 
        <td> 
        <asp:Label ID="lblstt" runat="server" Text=""></asp:Label> 
        </td> 
        <tr> 
         <td> 
         <asp:Label ID="Label1" runat="server" Text="Brand Name" CssClass="lbF"></asp:Label> 
        </td> 
        <td> 
         <asp:TextBox ID="txtbrdName" runat="server"></asp:TextBox> 
        </td> 
        </tr> 

       </tr> 
       <tr> 
        <td> 
         <asp:Button ID="BtnBrdName" runat="server" Text="Add" Width="70px" OnClick="Button1_Click" /> 
         <asp:Button ID="btncancel" runat="server" Text="Cancel" OnClick="btncancel_Click" /> 
        </td> 
       </tr> 
      </table> 
      </div> 
     </asp:Panel> 
    </div> 
</div> 
</ContentTemplate> 

</asp:UpdatePanel> 

如果我點擊btnAdd類文本框裏面的值應該去數據庫和彈出窗口....但我的項目中btnADD按鈕的點擊事件不發射和modalpopup正在工作....請給我一個解決方案..

+0

沒有btnAdd是我的按鈕...裏面的彈出窗口btnBrdNAme – sree

回答

4

我有同樣的問題,由於某種原因,當你設置一個按鈕作爲模式彈出的TargetControlID它禁用Click事件。

我克服這個問題的方法是在頁面上放置一個不可見/虛擬Label控件,並將該模式​​的TargetControlID屬性設置爲此Label.Then在您的btnAdd Click事件中從數據庫中獲取所有必需的值,調用ModalPopupExtender1.Show()顯示模態:

ASPX:

<form id="form1" runat="server"> 
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> 
</asp:ToolkitScriptManager> 
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <ContentTemplate> 
     <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="AddClick" /> 
     <asp:Label ID="dummyLabel" runat="server" /> 
     <asp:ModalPopupExtender ID="ModalPopupExtender1" PopupControlID="Panel1" TargetControlID="dummyLabel" 
      BackgroundCssClass="modalBackground" runat="server"> 
     </asp:ModalPopupExtender> 
     <asp:Panel ID="Panel1" align="center" CssClass="modalPopup" runat="server"> 
      <div class="body-reg-left"> 
       <table> 
        <tr> 
         <td> 
          <asp:Label ID="Label1" runat="server" Text="Brand Name" CssClass="lbF"></asp:Label> 
         </td> 
         <td> 
          <asp:TextBox ID="txtbrdName" runat="server"></asp:TextBox> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          <asp:Button ID="BtnBrdName" runat="server" Text="Add" Width="70px" OnClick="Add" /> 
          <asp:Button ID="btncancel" runat="server" Text="Cancel" OnClick="Cancel" /> 
         </td> 
        </tr> 
       </table> 
      </div> 
     </asp:Panel> 
     </div> </div> 
    </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" /> 
    </Triggers> 
</asp:UpdatePanel> 
</form> 

代碼後面:

protected void Add(object sender, EventArgs e) 
{ 
    //Add logic 
} 

protected void Cancel(object sender, EventArgs e) 
{ 
    //Cancel logic 
} 

protected void AddClick(object sender, EventArgs e) 
{ 
    txtbrdName.Text = "Some category"; //Populate the value as required 
    ModalPopupExtender1.Show(); 
} 
+0

我得到「modalpopupextender在當前上下文中不存在」錯誤 – Huzaifa

相關問題