This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16373|Reply: 0

[ASP.NET] Several common ways to pop up message boxes in ASP.NET

[Copy link]
Posted on 3/26/2015 11:33:50 AM | | |

This article examples describe several common methods for popping up message boxes in ASP.NET. Share it with you for your reference. The specific analysis is as follows:

In ASP.NET website development, it is often necessary to use the alert message box, especially when submitting web pages, it is often necessary to verify the data on the server side and give prompts or warnings.

Here, just a few different implementations are described.

1. The well-known method is to use the following code to implement:

  1. Response.Write("<scrip去掉t>alert('弹出的消息')</scrip去掉t>");
Copy code


This approach is undeniably the most commonly used and the simplest way to implement it. However, one of the main features of this method is that the pop-up message box is in a new blank page,
The user must close the message window before they can continue to display the page content.

So, why is this happening? This is because, by default, the alert function is added to the front of the page, and when it pops up, it will prevent the display of the page content.
As a result, the background page of the alert message box that the user sees is blank.

2. Use Page.RegisterStartupscrip to remove the t() method to register the page execution script, which will place the registered script at the end of the web form, that is,</form> before the markup.
This way, the pop-up message window will be executed after the content of the form is displayed, so the page will no longer be blank.
The code is as follows:

  1. this.Page.RegisterStartupscrip去掉t(" " , "<scrip去掉t>alert(' 弹出的消息 '); </scrip去掉t> ");
Copy code


Note that here is RegisterStartupscrip removing t, not RegisterClientscrip removing tBlock!

3. Considering that the window.onload() function is generally executed after the page is fully loaded, the alert message box function can be written in the window.onload() function.
This way, you can avoid blank pages.
The code is as follows:

  1. Response.Write(" <scrip去掉t>function window.onload() {alert( ' 弹出的消息' ); } </scrip去掉t> ");
Copy code


In summary, the first method will display the alert message box in a blank page, while the latter two methods will pop up the alert dialog box on the current page, and there will be no blank page.

I hope this article will be helpful to everyone's asp.net programming.





Previous:asp.net Implement the filling of the schedule table and the query code of yesterday's schedule
Next:Today, the campus network came to my aunt, and I was disconnected more than a dozen times a day!
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com