Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a simple yes/no popup in ASP.NET that return the result back to my c#?

With ASP.NET, how do I prompt the user for a yes/no question and getting the result back to my .ascx?

So far I can open a confirmation dialog with use of Javascript, but I can't return the value. But I don't know if this is the right approach.

like image 935
radbyx Avatar asked May 03 '11 09:05

radbyx


People also ask

How can show confirm box from code behind in asp net?

1) Form Design <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type = "text/javascript"> function Confirm() { var confirm_value = document. createElement("INPUT"); confirm_value. type = "hidden"; confirm_value.name = "confirm_value"; if (confirm("Do you want to save data?")) { confirm_value.

How do I go back in asp net?

If you want to use ASP.NET Button:history. back(1); return false;" />


1 Answers

You can use standart JavaScript confirm() function to show popup and do Post Back in case of Yes or No. For example:

if (confirm('Question')) {
    __doPostBack('', 'Yes_clicked');
} else {
    __doPostBack('', 'No_clicked')
}  

Then on server in Page_Load() method do:

if (IsPostBack)
{
    var result = Request.Params["__EVENTARGUMENT"];
}

You can also do it async by specifying the first parameter of __doPostBack() function as ID of any update panel.

like image 55
Sergey Metlov Avatar answered Sep 22 '22 00:09

Sergey Metlov