我已经在网上搜索过,并尝试了一些提供的解决方案,但没有一个对我有用。
我在一个 div 中有一个按钮。我在 jquery 对话框中显示 div。单击按钮在 jquery 对话框中不起作用。
我的代码如下:
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>
j查询
function ViewModelPopup2() {
$("#ViewModalPopupDiv2").dialog({
scrollable: true,
width: 800,
modal: true
});
}
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);
}
}
请让我知道我需要做什么来触发服务器控件事件。
最佳答案
我在使用 asp.net 按钮和 jQuery UI 对话框时也遇到了这个问题。
要解决它,您需要在您的 aspnet 按钮中将标记 UseSubmitBehavior
设置为 false
。
如果 UseSubmitBehavior
属性设置为 true(这是默认值),按钮将使用浏览器的提交机制(jQuery Dialog UI 正在操纵它),如果 UseSubmitBehavior
设置为 false,该按钮将使用 asp.net 框架包含在页面中的客户端脚本来发布到表单。
所以你的 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>
更多详情请访问 http://msdn.microsoft.com/library/system.web.ui.webcontrols.button.usesubmitbehavior.aspx
关于c# - 无法单击 jquery 对话框中的 asp.net 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18729306/