ASP. NET background operation Javascript:confirm return value

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.