与 jQuery UI 对话框交互后如何继续使用 asp.net 服务器端按钮单击方法?
来自 jQuery 菜鸟的任何帮助都值得赞赏,因为我已经浪费了太多时间,截止日期很快就到了。
内幕 - 我在 Intranet 工程应用程序中有一个 ASP.NET 表单,在某些情况下按下“提交”按钮时需要弹出一个 jQuery 对话框。
在“某些情况下”,用户需要确认问题,并且表单需要继续提交包括执行“提交”按钮的 Click 事件的服务器端代码。
当“某些情况”不存在时,表单只需提交并执行“提交”按钮的 Click 事件的服务器端代码。 (与上面相同,但没有 jQuery 对话框。)
挑战似乎是:
- 当对话框关闭时,表单会提交,但显然*不是*原来的提交按钮导致它,因为唯一的服务器端代码被执行是“页面加载”。未调用“cmdSave_Click”(这也是我需要执行的)。
这是对话框的定义。 (在两次单击按钮时,我需要在服务器端 cmdSave_Click 方法最终需要的隐藏字段中粘贴一个值。)
var dlgTidPopup = $('#popupPnlTid').dialog({
resizable: false,
autoOpen: false,
draggable: false,
modal: true,
closeOnEscape: false,
title: 'Request for Target Identifier (TID)?',
buttons: {
"yes": function () {
$('#txtTidYes').val("1");
$('#userInputForm').unbind("submit").submit();
$(this).dialog('close');
},
"no": function () {
$('#txtTidYes').val("0");
$('#userInputForm').unbind("submit").submit();
$(this).dialog('close');
}
}
});
dlgTidPopup.parent().appendTo($('form:first'));
这是提交部分。 if
语句确定对话框的外观以满足“这是某种情况吗?”要求。
$('#userInputForm').submit(function (event) {
if ($('#hdnSituationIsTid').val() == "1") {
event.preventDefault();
$('#popupPnlTid').dialog("open");
}
});
提交按钮看起来像:
<asp:ImageButton ID="ibtnSend" ImageUrl="../_common/Images/buttons/Send.gif"
runat="server" OnCommand="cmdSave_Click" CommandName="Send" CssClass="majorButton"
CausesValidation="false" />
这个问题的答案可能很简单,我只是缺乏知识。非常感谢任何指导。 (另外,我确实知道我已经搜索过并阅读了很多很多帖子,甚至根据其中许多帖子对我的代码进行了建模,但我还没有找到解决我的具体问题的方法。)
From a jQuery noob, any help is appreciated with this as I've wasted too much time already with a deadline fast approaching.
The lowdown - I have an asp.net form in an intranet engineering application that needs to pop up a jQuery dialog when the Submit button is pressed in certain circumstances.
In the "certain circumstances" the user needs to confirm a question and the form needs to continue with submission including executing the server-side code for the Submit button's Click event.
When the "certain circumstances" don't exist, the form needs to simply submit and execute the server-side code for the Submit button's Click event. (Same as above, but with no jQuery Dialog.)
The challenge seems to be:
- When the dialog closes, the form submits but it is obviously *not* as if the original Submit button caused it since the only server-side code being executed is `Page_Load`. The `cmdSave_Click' (which is what I also need to execute) is not called.
Here is the dialog box definition. (On both button clicks I need to stick a value in a hidden field that the server-side cmdSave_Click
method ultimately needs.)
var dlgTidPopup = $('#popupPnlTid').dialog({
resizable: false,
autoOpen: false,
draggable: false,
modal: true,
closeOnEscape: false,
title: 'Request for Target Identifier (TID)?',
buttons: {
"yes": function () {
$('#txtTidYes').val("1");
$('#userInputForm').unbind("submit").submit();
$(this).dialog('close');
},
"no": function () {
$('#txtTidYes').val("0");
$('#userInputForm').unbind("submit").submit();
$(this).dialog('close');
}
}
});
dlgTidPopup.parent().appendTo($('form:first'));
Here is the submission portion. The if
statement determines the appearance of the dialog to satisfy the "is this that certain circumstance?" requirement.
$('#userInputForm').submit(function (event) {
if ($('#hdnSituationIsTid').val() == "1") {
event.preventDefault();
$('#popupPnlTid').dialog("open");
}
});
The submit button looks like:
<asp:ImageButton ID="ibtnSend" ImageUrl="../_common/Images/buttons/Send.gif"
runat="server" OnCommand="cmdSave_Click" CommandName="Send" CssClass="majorButton"
CausesValidation="false" />
The answer to this is probably so simple and I am just lacking in knowledge. Any guidance is greatly appreciated. (Also, do know that I've scoured SO and read many, many posts and have even modeled my code after many of them, but I haven't quite found a resolution to my specific question.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅我对下面链接的问题的回答,我使用隐藏的
asp:button
作为回调
:带有 jQuery 弹出对话框的 ASP.NET:如何回发对话框关闭
See my answer on the question linked below, I use a hidden
asp:button
for thecallback
:ASP.NET with jQuery popup dialog: how to post back on dialog closing