The examples in this article describe several common methods for pop-up message boxes in asp.net. Share to everyone for your reference. The specific analysis is as follows:
In ASP.net web site development, often need to use the alert message box, especially when submitting web pages, often need to check the data on the server side, and give a hint or warning.
Here, only a few different implementations are described.
1, the well-known method is to use the following code to achieve:
Copy Code code as follows:
Response.Write ("<script>alert (' pop-up message ') </script>");
Admittedly, this method is the most commonly used, but also the simplest way to achieve a solution. However, one of the main features of this approach is that the pop-up message box is in a new, blank page,
Users must turn off the message window before they can continue to display the page content.
So, why is there such a situation? This is because, by default, the alert function is added to the front of the page, and when it pops up, it blocks the contents of the page.
Therefore, the background page of the alert message box that the user sees is blank.
2. Use the Page.registerstartupscript () method to register the page execution script, which will place the registered script at the end of the Web form, that is, before the </form> tag.
After the content of the form is displayed, the pop-up message window is not executed, so the page is no longer blank.
The code is as follows:
Copy Code code as follows:
This. Page.registerstartupscript ("" "," <script>alert (' pop-up message '); </script> ");
Note that this is registerstartupscript, not registerclientscriptblock!.
3, considering that the window.onload () function is typically performed after the page is completely loaded, you can write the Alert message box function in the Window.onload () function.
In this way, you can also prevent the page from appearing blank.
The code is as follows:
Copy Code code as follows:
Response.Write ("<script>function window.onload () {alert (' pop-up message ');} </script> ");
In summary, the first Method alert message box appears in a blank page, and the latter two methods are pop-up Alert dialog box on the current page without a blank page.
I hope this article will help you with the ASP.net program design.