[英]how to get the return value from a JS dialog box in asp.net without tying it to a button
How can one display a confirmation box & get the return value in C# code in ASP.NET without tying it to a button? 如何在ASP.NET中显示确认框并获取C#代码中的返回值而不将其绑定到按钮? I need to display the confirmation box from inside the event handler of a button if a certain condition is filled.
如果满足特定条件,则需要从按钮的事件处理程序中显示确认框。
Situation: 情况:
protected void okBtn_Click(object sender, EventArgs e)
{
if (blah)
{
bool answer = DisplayConfirmationBox();
}
}
Displaying it using JS is not really an issue, but getting the return value from it is. 使用JS显示它并不是真正的问题,但是从中获取返回值是一个问题。
Javascript is executed on the client, ASP.NET/C# on the server. Javascript在客户端ASP.NET/C#在服务器上执行。
To get the value from your JS Dialog Box to the server, so you can work with it in your server side code, you have to either store it in a (Hidden) Text Field and perform a PostBack or do an asynchronous AJAX request. 为了将值从JS对话框获取到服务器,以便可以在服务器端代码中使用它,必须将其存储在(隐藏)文本字段中并执行PostBack或执行异步AJAX请求。
For the first method see the HiddenField server control and to trigger a PostBack from JS you can use 对于第一种方法,请参见HiddenField服务器控件,并从JS触发PostBack,您可以使用
__doPostBack(control, arg);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.