Asp. Several common methods of pop-up message boxes in net _ Practical tips

Source: Internet
Author: User
Tags blank page

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.

Related Article

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.