[英]jQuery modal dialog and ASP.NET postback
I have a modal dialog on my page using jQuery that a user enters a password into. 我的页面上有一个使用jQuery的模式对话框,用户在其中输入密码。
It's a standard jQuery dialog and it works fine. 这是一个标准的jQuery对话框,效果很好。 I have linkbuttons in a datagrid that open the dialog using this code:
我在datagrid中有linkbutton,它使用以下代码打开对话框:
$('.needsVal').click(function () {
$("#login1").dialog('open');
id = $(this).attr('id');
return false;
});
The problem is later on in the page I make an Ajax call, and based on the value returned, I want to selectively fire a postback for the page. 问题稍后在页面中进行Ajax调用,并基于返回的值,我希望有选择地为页面触发回发。 The problem is the postback never fires.
问题是回发永远不会触发。 My postback code is as follows:
我的回发代码如下:
if (returnValue == "true") {
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(id, "", false, "", "", false, true));
return true;
}
else {
alert("Authentication failure!\nPlease check your password and try again.");
return false;
For some reason I can't get the postback to work with the modal dialog, and it's driving me nuts. 由于某种原因,我无法使回发与模式对话框一起使用,这使我发疯。 I had this working with a regular Javascript prompt, but I had to change it because there's no way to mask the password in a prompt.
我使用常规的Javascript提示进行此操作,但由于没有办法在提示中屏蔽密码,因此必须对其进行更改。
Any thoughts on how to get the postback to work? 关于如何使回发工作有什么想法?
id is a global variable that has the unique ID of the clicked button. id是具有单击按钮的唯一ID的全局变量。 I've confirmed that's being passed properly.
我已经确认可以通过。
I managed to get this to work. 我设法使它起作用。
What I found was there are two ASP.NET controls on the page - two gridviews, one with regular linkbuttons and another with a linkColumn. 我发现页面上有两个ASP.NET控件-两个gridview,一个带有常规的linkbutton,另一个带有linkColumn。
Because of the way the linkbuttons work in the two types of controls (linkbutton vs. commandbutton) I had to vary how I open the form, and how I interact with the prompt. 由于链接按钮在两种类型的控件中的工作方式(链接按钮与命令按钮),我不得不改变打开表单的方式以及与提示进行交互的方式。 I had to create two different events.
我不得不创建两个不同的事件。 (Maybe there's a way to do it with one, but I couldn't figure it out)
(也许有一种方法可以做到这一点,但我无法弄清楚)
What I finally wound up with jQuery wise: 我最终用jQuery明智地总结了什么:
//Click event for gridview 1 (standard linkbutton)
$('.needsVal').click(function () {
$("#login1").dialog('open');
id = $(this).attr('id');
return false;
});
//Click event for second gridview (command button)
$('.needsValSideMenu').click(function () {
var h = $(this).html();
script = h.substring(h.indexOf("\"") + 1, h.indexOf("\">"));
$("#login2").dialog('open');
return false;
});
//AJAX call for standard linkbutton grid
function checkPassword() {
var returnValue;
$.ajax({
async: false,
type: "POST",
url: "myservice.asmx/Authenticate",
data: { "password": pw.value },
dataType: "xml",
error: function () { alert("Unexpected Error!"); },
success: function (msg) {
returnValue = $(msg).find('boolean').text()
}
});
if (returnValue == "true") {
//alert(id.replace("_", "$"));
id = id.split("_").join("$");
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(id.replace("_","$"), "", true, "", "", false, true));
}
else {
alert("Authentication failure!\nPlease check your password and try again.");
}
}
//Call for second grid (command button) - need to get and execute the script associated with this button
function checkPasswordSideMenu() {
var returnValue;
$.ajax({
async: false,
type: "POST",
url: "myservice.asmx/Authenticate",
data: { "password": pw2.value },
dataType: "xml",
error: function () { alert("Unexpected Error!"); },
success: function (msg) {
returnValue = $(msg).find('boolean').text()
}
});
if (returnValue == "true") {
eval(script);
}
else {
alert("Authentication failure!\nPlease check your password and try again.");
}
}
I couldn't think of a way to do this in one method since I need to call a different checkPassword routine depending on which type of button was clicked. 我想不出一种在一种方法中执行此操作的方法,因为我需要根据单击的按钮类型来调用不同的checkPassword例程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.