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:
- 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:
- 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:
- 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.
|