Skip to content Skip to sidebar Skip to footer

Get Confirm-box Value Via Code-behind At C#

I want to get the value from side to confirm aspx bool type=false; type= ClientScript.RegisterStartupScript(typeof(Page), 'exampleScript', 'confirm('are you confirm?')', true);

Solution 1:

Doesn't sound like best of the approach (I mean you could show pop-up client side)... However, if you want to accomplish this...

You have have a hidden asp:Button on your aspx and attach a event handler to it and write the code that you want to have executed upon clicking Yes on the confirm button.

And modify your RegisterStartupScript as below

type=   ClientScript.RegisterStartupScript(typeof(Page), "exampleScript", "if(confirm('are you confirm?')) { document.getElementById('btn').click(); } ", true);

Solution 2:

booltype=false;

  "return confirm('are you confirm?')"if(type){
...
}

Solution 3:

I was facing the same issue. The below code worked for me.

ClientScript.RegisterStartupScript(typeof(Page), "exampleScript", "if(confirm(\"Are you sure?\")){ document.getElementById('Button1').click(); }", true);
<asp:Button ID="Button1" Visible="true" SkinID="button"  OnClick="Button1_Click"  runat="server" />

Use a hidden button and write the code on click event of the button. Please note that don't use visible="false" property to make the button hidden. Instead use style="display:none"

Post a Comment for "Get Confirm-box Value Via Code-behind At C#"