There are two ways to use confirm in asp:
1. Do not use ajax,confirm will cause also face refresh
2. Ajax is used and does not refresh
A. Without Ajax, you can use StringBuilder to do it.
(a) ASP. StringBuilder Control background Operation Javascript:confirm return value, this method is more cumbersome
1. Background Startup events
StringBuilder sb = new StringBuilder ();
Sb. Append ("<script language= ' JavaScript >");
Sb. Append ("Var val=window.confirm (' Is You sure! ');");
Sb. Append ("Window.document.getElementById (' TextBox1 '). Value=val;");
Sb. Append ("__doPostBack (' TextBox1 ', ');");
Sb. Append ("</script>");
This. RegisterStartupScript (System.Guid.NewGuid (). ToString (), SB. ToString ());
2. Front Code:
<asp:textbox id= "TextBox1" runat= "Server" autopostback= "true" ontextchanged= "textbox1_textchanged" ></asp: Textbox>
3. Text box ontextchanged= The background event code for "textBox1_TextChanged"
protected void textBox1_TextChanged (object sender, EventArgs e)
{
if ((TextBox) (sender)). Text! = "")
{
if ((TextBox) (sender)). Text.toupper () = = "TRUE")
{
Perform another event/method after determining
}
if ((TextBox) (sender)). Text.toupper () = = "FALSE")
{
Execute another Event/method after canceling
}
}
}
This event can also be written as other method drivers. Just judge the value of TexBox1.
Note: This event is caused by autopostback= "true" to refresh the page, the global variable is lost, it is best to use the session variable to save the value that needs to be stored.
(b) using the front-end JavaScript to determine the method of the background execution, there is a OnClientClick event this method is the simplest
Foreground button Event
<asp:button id= "Bt_deletebutton" runat= "Server" onclick= "Bt_deletebutton_click" onclientclick= "if (Confirm (' Invoke the background Bt_deletebutton_click event to confirm the continuation? ') {return true;} Else{return false;} " text= "Delete" visible= "False"/>
Just add it on the page
A.onclick Background events,
B.onclientclick event, JavaScript confirm, select OK after performing the onclick background is the event Bt_deletebutton_click
B: Pages that use AJAX controls
Scriptmanager.registerstartupscript (UpdatePanel1, Updatepanel1.gettype (), "", "alert (' hint"); if (Confirm (' Continue yes ') {alert (' Continue on this page ')}else{window.open (' productmanage.aspx ', ' _blank ');} ", true);
ASP. NET background operation Javascript:confirm return value