Close the page code and pop-up window, appear OK, Cancel button + Execute

Source: Internet
Author: User

Close the current page: <a href= "Javascript:window.opener=null;window.close ();" > Close </a>, if the button is:

Response.Write ("<script language=/" javascript/">window.opener=null;window.close ();</script>");

This will not pop up as the current window is trying to close the dialog box.

So how about when the user-point browser maximizes the Close button in the Close button, it also pops up the closed confirmation dialog box? This way:

<body onbeforeunload= "Return" really want to close this window? ' " > In this case, the onbeforeunload function will be executed when the point is closed, pop the dialog box that really wants to close this window, click Cancel return false, do not close, point OK return true close window

So how can you click a button when the pop-up OK Cancel dialog box?? If you do not execute the following code if you click Cancel, click OK to continue with the following code?

Write in the click of the button:

Response.Write ("<script language=/javascript/" > "+" if (Confirm (/"OK?/")) "+" {window.location.href= ' Default.aspx ';} ' + "Else{history.back ();}" + "</script>");

This means: first with the Confirm function pop-up with a certain cancellation dialog box, if you click OK to return to true, the implementation of the window.location.href= ' default.aspx ' code, if the point of cancellation on the return of false, on the implementation of History.back () ; Go back to the original page

Of course, we can also write this:

private void Btnchong_click (object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Write ("<script language=/" javascript/">" + "if (!confirm) (Are you sure you want to recharge it?/") "+" {history.back ();} "+" </ Script> ");
First pops up a dialog box with a OK Cancel button, and if the point is canceled, return to the original page and the following code will not be executed
String connstring = configurationsettings.appsettings["ConnStr"]. ToString () + Server.MapPath (Request.applicationpath) + "Hualong.mdb ";
OleDbConnection conn = new OleDbConnection (connstring);
String selstring = "Select Count (*) from myuser where name = @name";
OleDbCommand comm = new OleDbCommand (selstring,conn);
Conn. Open ();
Comm. Parameters.Add (New OleDbParameter ("@name", oledbtype.varchar,50));
Comm. parameters["@name"]. Value = TxtZhang.Text.ToString (). Trim ();
int i = (int) Comm. ExecuteScalar ();
Conn. Close ();
if (i==0)//If the account does not exist
{
Response.Write (' <script>alert (' account not correct! ') </script> ");
Return;//return all the code below will not be executed
}
else//if the account exists and then executes the following code
{
String selString1 = "Select Count (*) from haoma where Kahao = @kahao and Mima = @mima and Youxiao = ' valid '";
OleDbCommand comm1 = new OleDbCommand (selstring1,conn);
Conn. Open ();
Comm1. Parameters.Add (New OleDbParameter ("@kahao", oledbtype.varchar,50));
Comm1. Parameters.Add (New OleDbParameter ("@mima", oledbtype.varchar,50));
Comm1. parameters["@kahao"]. Value = TxtKa.Text.ToString (). Trim ();
Comm1. parameters["@mima"]. Value = En.encryption (txtPass.Text.ToString (). Trim (), "16899168");//Encrypt password
int II = (int) comm1. ExecuteScalar ();
Conn. Close ();
if (ii==0)//If the card record does not exist or has been recharged
{
Response.Write ("<script language=/" javascript/) >alert (' card number or wrong password! '); </script> ");
return;//does not execute the following code
}
Else
{
String selstr = "Select Over_date from myuser where name = @name";
Remove the user expiration field from the MyUser table
OleDbCommand COMM11 = new OleDbCommand (selstr,conn);
Conn. Open ();
Comm11. Parameters.Add (New OleDbParameter ("@name", oledbtype.varchar,50));
Comm11. parameters["@name"]. Value = TxtZhang.Text.ToString (). Trim ();
OleDbDataReader dr = Comm11. ExecuteReader ();
Dr. Read ();
DateTime overdate = new DateTime ();
Overdate = Dr. GetDateTime (0);
Dr. Close ();
Conn. Close ();
String upstring = "Update haoma set Youxiao = ' Invalid ', Zhanghao = @zhanghao, ch_date = @ch_date where Kahao = @kahao";
Update the database record so that the card number is in a failed state and write the user recharge record
String upString1 = "Update myuser set over_date = @over_date WHERE name = @name";
Update data record user account expiration date plus one months
OleDbCommand comm22 = new OleDbCommand (upstring,conn);
Conn. Open ();
Comm22. Parameters.Add (New OleDbParameter ("@youxiao", oledbtype.varchar,50));
Comm22. Parameters.Add (New OleDbParameter ("@zhanghao", oledbtype.varchar,50));
Comm22. Parameters.Add (New OleDbParameter ("@ch_date", oledbtype.date));
Comm22. Parameters.Add (New OleDbParameter ("@kahao", oledbtype.varchar,50));
Comm22. parameters["@zhanghao"]. Value = TxtZhang.Text.ToString (). Trim ();
Comm22. parameters["@ch_date"]. Value = DateTime.Now;
Comm22. parameters["@kahao"]. Value = TxtKa.Text.ToString (). Trim ();
Comm22. ExecuteNonQuery ();
Conn. Close ();
OleDbCommand comm33 = new OleDbCommand (upstring1,conn);
Comm33. Parameters.Add (New OleDbParameter ("@over_date", oledbtype.date));
Comm33. Parameters.Add (New OleDbParameter ("@name", oledbtype.varchar,50));
Comm33. parameters["@name"]. Value = TxtZhang.Text.ToString (). Trim ();
if (Overdate > DateTime.Now)
{
Comm33. parameters["@over_date"]. Value = overdate.addmonths (1);
}
Else
{
Comm33. parameters["@over_date"]. Value = DateTime.Now.AddMonths (1);
}
Conn. Open ();
Comm33. ExecuteNonQuery ();
Conn. Close ();
Response.Write ("<script language=/" javascript/) >alert (' recharge success, I wish to learn to start a happy. ');</script> ");
}
}
}

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.