Using confirm in can be divided into two types:
1. Not using ajax, confirm will cause refresh
2. If ajax is used, it will not be refreshed
A. Without using ajax, you can use StringBuilder to complete it.
(1) Use StringBuilder to control the background operation javascript:confirm return value, this method is more cumbersome
1. Backend startup event
StringBuilder sb = new StringBuilder(); ("<script language='javascript'>"); ("var val=('Are you sure!');"); ("('TextBox1').value=val;"); ("__doPostBack('TextBox1','');"); ("</script>"); (().ToString(), ());
2. Foreground code:
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
3. Background event code of text box OnTextChanged="TextBox1_TextChanged"
protected void TextBox1_TextChanged(object sender, EventArgs e) { if (((TextBox)(sender)).Text != "") { if (((TextBox)(sender)).() == "TRUE") { //Execute another event/method after confirmation} if (((TextBox)(sender)).() == "FALSE") { //Execute another event/method after cancel } } }
This event can also be written as other method drivers. Just judge the value of TexBox1.
Note: This event causes page refresh by AutoPostBack="true" and global variables are lost. It is best to use the session variable to save the value that needs to be stored.
(2) Determine the method of background execution through front-end Javascript, and there is an OnClientClick event. This method is the simplest
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 to continue?')){return true;}else{return false;}" Text="Delete" Visible="False" />
Add it on the page
Backstage events,
Event, JavaScript confirm, select OK and execute OnClick background is event bt_DeleteButton_Click
B: Page using Ajax control
(UpdatePanel1, (), "", "alert('Hint'); if(confirm('Where to continue executing yes)){alert('Continue to add this page')}else{('','_blank');}", true);