In Asp.net, response. Write ("Alert ('error information');");

Source: Internet
Author: User

If response. write ("<SCRIPT> alert ('error information'); </SCRIPT>"); click "OK", which may cause "dislocation" of the page ";

Encapsulate the code into a class (called pagehelper. CS), which can be conveniently called on other pages;

For example, you can call page. Alert (this, "") on other pages. The effect is the same as that of the above Code. Do you have to say something different? That is, this writing method is much more perfect than above.

You can also have the second parameter, that is, page. Alert (this, "Warning ~ ","~ /Default. aspx ");

 

/**
*
* Description: Page Assistant class. A warning dialog box is displayed;
*
* Design by: recall;
*
* Creation date:
*
**/

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Web. UI;

Namespace newssystem. commonutility
{
Public static class pagehelper
{
Public static void alert (page objpage, string message)
{
String key = "alertmessage ";
String script = string. Format ("alert ('{0}')", message );
Objpage. clientscript. registerstartupscript (typeof (PAGE), key, script, true );
}

Public static void alert (page objpage, string message, string URL)
{
String key = "alertmessage ";
String script = string. Format ("alert ('{0}'); window. Location = '{1}';", message, URL );
Objpage. clientscript. registerstartupscript (typeof (PAGE), key, script, true );
}
}
}

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.