Asp.net background javascript: confirm return value, asp. netconfirm
In asp.net, confirm can be divided into two types:
1. If ajax is not used, confirm will also cause refreshing.
2. If ajax is used, it will not be refreshed.
A. If ajax is not used, you can use StringBuilder.
(1) asp.net uses StringBuilder to control the return value of javascript: confirm in background operations. This method is cumbersome.
1. Background startup events
StringBuilder sb = new StringBuilder ();
Sb. Append ("<script language = 'javascript '> ");
Sb. Append ("var val = window. confirm ('Are you sure! ');");
Sb. Append ("your own Doc ument. getElementById ('textbox1'). value = val ;");
Sb. Append ("_ doPostBack ('textbox1 ','');");
Sb. Append ("</script> ");
This. RegisterStartupScript (System. Guid. NewGuid (). ToString (), sb. ToString ());
2. Front-end code:
<Asp: TextBox ID = "TextBox1" runat = "server" AutoPostBack = "true" OnTextChanged = "textbox#textchanged"> </asp: TextBox>
3. Background Event code of the text box OnTextChanged = "TextBox1_TextChanged"
Protected void TextBox1_TextChanged (object sender, EventArgs e)
{
If (TextBox) (sender). Text! = "")
{
If (TextBox) (sender). Text. ToUpper () = "TRUE ")
{
// Execute another event/method after confirmation
}
If (TextBox) (sender). Text. ToUpper () = "FALSE ")
{
// Execute another event/method after cancellation
}
}
}
This event can also be written as another method driver. Only determine the value of TexBox1.
Note: This event is caused by AutoPostBack = "true" to refresh the page, and global variables are lost. It is best to use session variables to save the values to be stored.
(2) determine the method to be executed in the background by using the front-end Javascript, and an OnClientClick event is added, which is the simplest method.
Foreground button event
<Asp: Button ID = "bt_DeleteButton" runat = "server" OnClick = "bt_DeleteButton_Click" OnClientClick = "if (confirm ('Call the background bt_DeleteButton_Click event. Are you sure you want to continue? ') {Return true;} else {return false;} "Text =" delete "Visible =" False "/>
Add
A. OnClick background event,
B. OnClientClick event, confirm of javascript. After you select OK, run the OnClick event bt_DeleteButton_Click in the background.
B: pages with Ajax controls
ScriptManager. registerStartupScript (UpdatePanel1, UpdatePanel1.GetType (), "", "alert ('hprompt '); if (confirm ('whether to continue executing yes )) {alert ('add more on this page ')} else {window. open ('productmanage. aspx ',' _ blank ');} ", true );
Aspnet c # How do I use functions such as confirm in the background page code and obtain the bool return value? Functions like messagebox
Store the value returned by confirm in a hidden domain and obtain it in the background.
<Input type = "hidden" id = "abc" runat = "server"/>
<Script>
Function check (){
If (window. confirm ("AB ")){
Document. getElementById (""). value = true;
Return true;
}
Else {
Document. getElementById (). value = false;
Return false;
}
}
</Script>
How to control the branch of the confirm return value in javascript
I wrote a general example, but I don't know how you dynamically generate a prompt box.
--------------------------------------------
I didn't see the context, but I don't know where you actually generated this judgment. I wrote a sample code to change the if (overwrite) position as needed, it seems that you are judging in <%>.
<Script>
<% Boolean overwrite = false; %>
Function doClick (){
If (confirm ('file already exists! Are you sure you want to overwrite it? ') <% Overwrite = true; %> // return after the point is canceled.
If (<% = overwrite %> ){
Alert ('upload ');
} Else {
Alert ('cancel upload ');
}
}
</Script>
<Input type = "button" name = "btnCheck" value = "Click" onclick = "doClick ()"/>