Several common methods for pop-up message boxes in ASP. NET, asp.net pop-up message boxes

Source: Internet
Author: User

Several common methods for pop-up message boxes in ASP. NET, asp.net pop-up message boxes

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

In ASP. NET website development, you often need to use alert message boxes. Especially when submitting a webpage, you often need to check the data on the server side and give a prompt or warning.

Here, we only introduce several different implementation methods.

1. The well-known method is implemented using the following code:Copy codeThe Code is as follows: Response. Write ("<script> alert ('pop-up message') </script> ");
It is undeniable that this method is the most common and simple implementation solution. However, the pop-up message box is displayed on a new blank page,
You must close the message window to continue displaying the page content.

So why is this happening? This is because, by default, the alert function is added to the top of the page. when it pops up, the page content is blocked,
Therefore, the background page of the alert message box is blank.

2. Use the Page. RegisterStartupScript () method to register the Page execution script. The registered script is placed at the end of the Web form, that is, before </form> is marked.
In this way, the message window is displayed after the form content is displayed, so the page will not be blank.
The Code is as follows:Copy codeThe Code is as follows: this. Page. RegisterStartupScript ("", "<script> alert ('pop-up message'); </script> ");

Note: This is RegisterStartupScript, not RegisterClientScriptBlock!

3. Considering that the window. onload () function is generally executed after the page is fully loaded, you can write the alert message box function in the window. onload () function.
In this way, you can avoid blank pages.
The Code is as follows:Copy codeCode: Response. Write ("<script> function window. onload () {alert ('pop-up message') ;}</script> ");

In summary, the alert message box is displayed on a blank page in the first method, and the alert dialog box is displayed on the current page in the last two methods without blank pages.

I hope this article will help you design your asp.net program.

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.