按钮单击事件未触发但modalpopupextender正在运行

时间:2012-12-07 07:05:56

标签: c# asp.net html ajax

在我的项目中 我有

    

 <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按钮的click事件没有触发,modalpopup工作....请给我是一个解决方案..

1 个答案:

答案 0 :(得分:5)

我遇到了同样的问题,出于某种原因,当你将一个按钮设置为模态弹出窗口的TargetControlID时,它会禁用Click事件。

我克服这个问题的方法是在页面上放置一个不可见/虚拟的Label控件,并将模态的TargetControlID属性设置为此Label.Then在你的btnAdd Click事件中从db获取所有必要的值并简单地调用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();
}