JQuery用户界面对话框和放大器;天冬氨酸(web窗体)调用事件处理程序 [英] JQuery UI Dialog & Asp (web forms) calling event handler
问题描述
我有一个提交按钮的形式。在点击提交按钮,我显示与确认和取消jQueryUI的对话框。在点击确认,我想回发,然后调用提交按钮的事件处理程序不是Page_Load事件。
我有以下
HTML
<输入类型=提交值=提交ID =提交=服务器的onclick =提交/>
JQuery的
$(#对话)。对话框('选项','按钮',{
确认:功能(){
$(#ctl01)提交()。
},
取消:功能(){
$(本).dialog(亲密);
}
});
到目前为止,这将调用Page_Load事件,因为我'只是'提交整个表单。
服务器端
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
如果(Page.IsPostBack)
result.Text + =嘿嘿后回来了,我们做到了!
} 保护无效提交(对象发件人,EventArgs的发送)
{
result.Text + =嘿嘿,事件处理程序!
}
从您的文章我要简单转到服务器端事件,而在对话按钮点击。
所以,我创建了一个隐藏
ASP服务器按钮
和触发它从确认按钮点击。
下面是工作code。
< HTML的xmlns =http://www.w3.org/1999/xhtml>
<头=服务器>
<标题>< /标题>
<链接HREF =CSS / UI的亮度/ jQuery的-UI-1.8.16.custom.css的rel =stylesheet属性类型=文/ CSS/> <脚本SRC =JS / jQuery的-1.6.2.min.js类型=文/ JavaScript的>< / SCRIPT> <脚本SRC =JS / jQuery的-UI-1.8.16.custom.min.js类型=文/ JavaScript的>< / SCRIPT>< /头>
<身体GT;
<表ID =form1的=服务器>
< DIV ID =对话的风格=显示:无称号=清空回收站吗?>
&所述p为H.;
<跨度类=UI图标UI图标警戒的风格=浮动:左;保证金:0 7px的20像素的0;>< / SPAN>
这些项目将被永久删除,无法恢复。你确定< / P>
< / DIV> <脚本>
jQuery的(函数(){
VAR DLG =的jQuery(#对话)。对话框({
拖动:真实,
可调整大小:真实,
显示:'转移',
隐藏:'转移',
宽度:320,
的AutoOpen:假的,
了minHeight:10,
了minWidth:10,
纽扣: {
确认:功能(){
$(#<%= btnNew.ClientID%GT;)。点击();
},
取消:功能(){
$(本).dialog(亲密);
}
}
});
。dlg.parent()appendTo(jQuery的(形式:一是));
}); jQuery的(文件)。就绪(函数(){
jQuery的(#提交)。点击(函数(五){
jQuery的('#对话)对话框(开放)。
}); }) < / SCRIPT> <输入类型=按钮值=提交ID =提交/>
< ASP:按钮=服务器风格=显示:无ID =btnNew文本=提交的OnClick =btnNew_Click/>
< /表及GT;
< /身体GT;
< / HTML>
在_Default.asp.cs
公共部分类_Default:System.Web.UI.Page
{
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
} 保护无效btnNew_Click(对象发件人,EventArgs的发送)
{
result.Text + =嘿嘿,事件处理程序!
}
}
I have a form with a submit button. On clicking the submit button, i display a jqueryUI dialog with Confirm and Cancel. On clicking Confirm, I want to post back and call the submit button's event handler not the Page_Load event.
I have the following
HTML
<input type="submit" value="Submit" id="submit" runat="server" onclick="submit" />
JQuery
$("#dialog").dialog('option', 'buttons', {
"Confirm": function () {
$("#ctl01").submit();
},
"Cancel": function () {
$(this).dialog("close");
}
});
so far, this will call the page_load event because i am 'just' submitting the whole form.
Server side
protected void Page_Load(object sender, EventArgs e)
{
if(Page.IsPostBack)
result.Text += "hey post-back, we did it!";
}
protected void submit(object sender, EventArgs e)
{
result.Text += "hey, event handler! ";
}
From your post I got that you want to simple go to the server side event while clicking on the button in the Dialog.
So I created a Hidden
ASP Server Button
and triggering it's click from the Confirm button.
Here is the working code.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="CSS/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
<script src="JS/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="JS/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="dialog" style="display: none" title="Empty the recycle bin?">
<p>
<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
<script>
jQuery(function() {
var dlg = jQuery("#dialog").dialog({
draggable: true,
resizable: true,
show: 'Transfer',
hide: 'Transfer',
width: 320,
autoOpen: false,
minHeight: 10,
minwidth: 10,
buttons: {
"Confirm": function() {
$("#<%=btnNew.ClientID %>").click();
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
dlg.parent().appendTo(jQuery("form:first"));
});
jQuery(document).ready(function() {
jQuery("#submit").click(function(e) {
jQuery('#dialog').dialog('open');
});
})
</script>
<input type="button" value="Submit" id="submit" />
<asp:Button runat="server" Style="display: none" ID="btnNew" Text="Submit" OnClick="btnNew_Click" />
</form>
</body>
</html>
In _Default.asp.cs
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnNew_Click(object sender, EventArgs e)
{
result.Text += "hey, event handler! ";
}
}
这篇关于JQuery用户界面对话框和放大器;天冬氨酸(web窗体)调用事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!