简体   繁体   English

无法在jquery对话框中单击asp.net按钮

[英]Cannot click on an asp.net button within a jquery dialog

I already did search online, and try a few solutions provided, but none of them are working for me. 我已经在线搜索过,并尝试了一些解决方案,但没有一个能为我工作。

I have a button within a div. 我在div中有一个按钮。 I am displaying the div within a jquery dialog. 我在jquery对话框中显示div。 The button click doesnt work within the jquery dialog. 按钮单击在jquery对话框中不起作用。

I have my code below : 我的代码如下:

aspx ASPX

    <div id='one'>
 <asp:LinkButton ID="ConfigureAlerts" OnClick="btnConfigureAlerts_Click" runat="server">Configure Alerts</asp:LinkButton>
</div>
<div id="ViewModalPopupDiv2">
        <asp:UpdatePanel ID="UpdatePanel3" runat="server">
            <ContentTemplate>
            <asp:Panel ID="Panel2" runat="server" HorizontalAlign="left" ScrollBars="Auto">
            <asp:Button ID="btnGetLogs" runat="server" Text="SendAlerts" OnClick="btnSendAlertEmail_Click"/>
            </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

jquery jQuery的

function ViewModelPopup2() {
            $("#ViewModalPopupDiv2").dialog({
                scrollable: true,
                width: 800,
                modal: true
            });
        }

aspx.cs aspx.cs

protected void btnSendAlertEmail_Click(object sender, EventArgs e)
        {

            // Code to send email

        }

protected void btnConfigureAlerts_Click(object sender, EventArgs e)
        {

        ScriptManager.RegisterStartupScript
                       (this, this.GetType(), "callScriptFunction", "ViewModelPopup2();", true);
        }
    }

Please let me know what I need to do , to trigger the server control events . 请让我知道我需要做什么,以触发服务器控制事件。

I also had this problem with asp.net buttons and jQuery UI Dialog. 我也有asp.net按钮和jQuery UI Dialog的这个问题。 To solve it you need to set in your aspnet button the tag UseSubmitBehavior to false . 要解决此问题,您需要在aspnet按钮中将标签UseSubmitBehaviorfalse

If UseSubmitBehavior attribute is set to true (this is the default value), the button will use the browser's submit mechanism (and jQuery Dialog UI is manipulating it), if UseSubmitBehavior is set to false , the button will use a client-side script that asp.net framework includes in the page to post to the form. 如果UseSubmitBehavior属性设置为true (这是默认值),该按钮将使用浏览器的提交机制(并且jQuery Dialog UI正在操作它),如果UseSubmitBehavior设置为false ,该按钮将使用客户端脚本asp.net框架包含在页面中发布到表单。

So your HTML should be like this : 所以你的HTML应该是这样的:

<div id='one'>
<asp:LinkButton ID="ConfigureAlerts" OnClick="btnConfigureAlerts_Click" runat="server">Configure Alerts</asp:LinkButton>
</div>
<div id="ViewModalPopupDiv2">
        <asp:UpdatePanel ID="UpdatePanel3" runat="server">
            <ContentTemplate>
            <asp:Panel ID="Panel2" runat="server" HorizontalAlign="left" ScrollBars="Auto">
            <asp:Button ID="btnGetLogs" runat="server" Text="SendAlerts" OnClick="btnSendAlertEmail_Click" UseSubmitBehavior="false" />
            </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

More details at http://msdn.microsoft.com/library/system.web.ui.webcontrols.button.usesubmitbehavior.aspx 更多详细信息,请访问http://msdn.microsoft.com/library/system.web.ui.webcontrols.button.usesubmitbehavior.aspx

This is the classic, thanks for moving my dialog jQuery, question. 这是经典,感谢我移动我的对话框jQuery,问题。

jQuery UI for some reason moves your dialog code to the bottom of the html markup, outside of your form tag. jQuery UI由于某种原因将对话框代码移动到表单标记之外的html标记的底部。 You need to move the dialog back into the form with some more jQuery: 您需要使用更多jQuery将对话框移回到表单中:

dlg.parent().appendTo(jQuery('form:first'));

where dlg is your jQuery.UI dialog object. 其中dlg是你的jQuery.UI对话框对象。

        var dlg = $("#ViewModalPopupDiv2").dialog({
            scrollable: true,
            width: 800,
            modal: true
        });
        dlg.parent().appendTo(jQuery('form:first'));

That should get things working for you again. 这应该让事情再次为你效劳。 Cheers! 干杯!

If that doesn't work, try doing that in the open event: 如果这不起作用,请尝试在open事件中执行此操作:

open: function(type,data) { $(this).parent().appendTo("form"); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM