【问题标题】:ModalPopupExtender bypassing OnClickModalPopupExtender 绕过 OnClick
【发布时间】:2012-05-10 19:07:27
【问题描述】:

嘿,所以我对 asp.net 还是很陌生,我正在尝试创建一个网站/表单,它可以接收大量数据并用它做一些事情。我有一个调用 submitButton_Click 方法的提交按钮,但是当我在服务器端对同一事件进行处理时,我也有一个显示“请稍候”更新面板的 modalpopup。问题是 modalpopup 似乎工作正常,但它抑制了我的 submitButton_Click 方法调用。我该怎么办?

另外,是否有可能在更新面板打开时调用默认方法?尽管我上次更新它,但我希望面板每次弹出时都相同。

<asp:Button ID="submitButton" runat="server" Text="Submit" OnClick="submitButton_Click"
            CssClass="buttons"/>

<asp:ModalPopupExtender 
        ID="modalProgress" 
        runat="server" 
        OkControlID="btnOkay" 
        TargetControlID="submitButton" 
        PopupControlID="progessPanel"
        BackgroundCssClass="modalBackground">

</asp:ModalPopupExtender>

【问题讨论】:

    标签: asp.net asp.net-ajax


    【解决方案1】:

    它不会绕过点击事件;它只是将客户端 onclick 更改为返回 false,从而否定回发。老实说,我一直觉得这很痛苦。幸运的是,有一个解决方法:

    <asp:Button ID="submitButton" runat="server" Text="Submit" OnClick="submitButton_Click"                CssClass="buttons"/>
    <!-- hidden button to satisfy the extender -->
    <asp:Button ID="hiddenButton" runat="server" style="display:hidden" />
    
    <asp:ModalPopupExtender 
            ID="modalProgress" 
            runat="server" 
            OkControlID="btnOkay" 
            TargetControlID="hiddenButton" 
            PopupControlID="progessPanel"
            BackgroundCssClass="modalBackground">
    </asp:ModalPopupExtender>
    

    通过添加隐藏按钮,您将满足扩展程序的要求,并且您可以在提交按钮的单击事件中以代码隐藏的方式打开对话框:

    protected void submitButton_Click(object sender, EventArgs e)
    {
        //display the modal dialog
        modalProgress.Show();
    }
    

    【讨论】:

    • 我过去见过这种方法,但我不喜欢有一个按钮只是为了“满足”PopUpControlExtender 的想法。我发布了一个可能工作的替代方案-我没有测试它-。
    • @Icarus:是的,我也不喜欢。不幸的是,有时您需要在显示扩展器之前执行逻辑。我使用RadToolTip 已经有一段时间了,主要是因为这个原因。
    • +1 我的代码不起作用。 ModalPopUpExtender 需要指定 TargetControlID。
    猜你喜欢
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 2010-10-22
    • 2019-06-29
    • 1970-01-01
    • 1970-01-01
    • 2020-02-22
    • 2015-07-01
    相关资源
    最近更新 更多