我试图在用户单击 ASP.Net 按钮时显示模式对话框。这是我的页面:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.6.custom.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#dialog").dialog({
bgiframe: true,
autoOpen: false,
height: 300,
modal: true,
buttons: {
'Ok': function() {
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
},
close: function() {
;
}
});
});
function ShowDialog() {
$('#dialog').dialog('open');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="TreeNew" runat="server" Text="New" OnClientClick="ShowDialog();"/>
<asp:Label ID="Message" runat="server"></asp:Label>
<div id="dialog" title="Select content type">
<p id="validateTips">All form fields are required.</p>
<asp:RadioButtonList ID="ContentTypeList" runat="server">
<asp:ListItem Value="1">Text</asp:ListItem>
<asp:ListItem Value="2">Image</asp:ListItem>
<asp:ListItem Value="3">Audio</asp:ListItem>
<asp:ListItem Value="4">Video</asp:ListItem>
</asp:RadioButtonList>
</div>
</div>
</form>
</body>
</html>
当我点击 TreeNew 按钮时出现模态弹出窗口,但页面立即执行回发。
发生了什么事?
最佳答案
同时添加 return false;
将解决您的问题(如其他答案所建议的那样),我认为您最好的办法是使用标准的 HTML 按钮。在这种情况下没有理由使用 ASP.NET 控件,因为您不打算回发。
但是,如果您坚持使用 ASP.NET 按钮,至少设置 UseSubmitBehavior="False"
这样按钮就会呈现为 <input type="button"/>
而不是 <input type="submit"/>
.
关于c# - 使用 ASP.NET 按钮显示的 jQuery UI 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2321156/