Search code examples
c#javascriptasp.netcode-behindconfirm

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);

if(type){
...
}

How do I get the value of?


Solution

  • 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);