Reputation: 1872
How can one display a confirmation box & get the return value in C# code in ASP.NET without tying it to a button? 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.
Upvotes: 0
Views: 598
Reputation: 13018
Javascript is executed on the client, ASP.NET/C# on the server.
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.
For the first method see the HiddenField server control and to trigger a PostBack from JS you can use
__doPostBack(control, arg);
Upvotes: 1