我要做的是弹出一个div包含两个反馈按钮。一个按钮用于取消,另一个按钮用于提交(使用服务器端)。
HTML
<div id="message" style="display:none">
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/ClearButton.png"
onclick="ImageButton1_Click1"/>
</div>
JAVASCRIPT
<script type="text/javascript">
$(document).ready(function () {
/*$('div#message').dialog({ autoOpen: false })*/
$('#hlfeedback').click(function () {
$('div#message').dialog({
width: 608,
height: 750,
modal: true,
overlay: { backgroundColor: "#000", opacity: 0.5 },
buttons: {},
open: function (event, ui) {
$(".ui-dialog-titlebar-close").hide();
}
});
});
$('#ImageButton1').click(function () {
$('div#message').dialog({
close: function (event, ui) { $(this).close(); }
});
});
})</script>
Server Side
protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
{
//Not working
}
服务器端根本不起作用。以及使用JavaScript的关闭按钮。我想从服务器端使用按钮提交数据库。
要获得服务器端事件的工作,您需要对话框才能成为<form runat='server'>
标签的孩子(通常在每个ASPX页面上)。
使用jQuery创建对话框时,它不会自动添加为form
的孩子,因此您的服务器端代码未被调用。
可以很容易地修复这一点,添加: $(this).parent().appendTo("form");
到对话框的打开功能,例如:
$('div#message').dialog({
width: 608,
height: 750,
modal: true,
overlay: { backgroundColor: "#000", opacity: 0.5 },
buttons: {},
open: function (event, ui) {
$(this).parent().appendTo("form");
$(".ui-dialog-titlebar-close").hide();
}
});