Skip to content Skip to sidebar Skip to footer

Yes/no Messagebox In Asp.net

I want to use JavaScript Message-Box in ASP.Net with Yes/No option. The scenario is, when I am calling the JavaScript function on a Client_click event of a button, its working fine

Solution 1:

Your code will do not wait for the confirmation value at the server side. Page.ClientScript.RegisterStartupScript will just register the client script and that moment that methods execution will be completed. And it will go on with the next line of the code. It is not the responsibility of the server to handle the registered javascript code. So if you want to achieve the Yes/NO confirmation and wait to server side use the AjaxModelPopupExtender with the custom code that will give you what you need. Here you can get more info on how to use the ajaxmodel pop up extender.

Solution 2:

You should not do it as you are doing. Coder of Code is right. Do client stuff at client side and come to server with some data to process or decision to process.

In your case you just need to write Javascript function and trigger that function when you want. If the response is yes then do postback or Ajax. If not then just stay on page.

Sample javascipt function will be as below-

<scriptlanguage="javascript"type="text/javasctipt">functiongetConfirmation(){
var r = confirm("Press a button!");
   if (r == true) {
      returntrue;
   } else {
      returnfalse;
 }
}
</script>

You can directly call this in action like -

return confirm("Confirm Input");

If you want to use nice custom UI then you can use Ajax Modelpopupextender in Ajax control toolkit.

http://www.codeproject.com/Articles/34996/ASP-NET-AJAX-Control-Toolkit-ModalPopupExtender-Co

Post a Comment for "Yes/no Messagebox In Asp.net"