Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button Click Event is not firing but modalpopupextender is working

in my project i have

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

enter code here
Admin - *If 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>

if i click the btnAdd the value inside category textbox should go to database and popup the window .... but in my project the btnADD button's click event is not firing and modalpopup is working.... please give me a solution..

like image 549
sree Avatar asked Dec 07 '12 07:12

sree


1 Answers

I've had the same problem, for some reason when you set a button as the TargetControlID of the modal popup it disables the Click event.

The way I overcame this issue was by placing an invisible/dummy Label control on the page and setting the TargetControlID property of the modal to this Label.Then in your btnAdd Click event get all the necessary values from the db and simply call the ModalPopupExtender1.Show() to display the modal:

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>

Code behind:

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();
}
like image 95
Denys Wessels Avatar answered Sep 28 '22 20:09

Denys Wessels