ASP. NET pop-up dialog box base class (output alet warning box)

Source: Internet
Author: User

Today, when I was writing a webpage on ASP.net, I encountered a problem with a pop-up warning box. I found it online. The following article is not bad.

Reproduced to share with you (reproduced: http://www.cnblogs.com/feifeiwzh/articles/1267892.html)

Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. text;

Namespace EC
{
/// <Summary>
/// General information output method
/// </Summary>
Public class messageobject
{  
 
/// <Summary>
/// General output
/// </Summary>
/// <Param name = "str"> </param>
Public static void write (string Str)
{
System. Web. httpcontext. Current. response. Write (STR );
}  
/// <Summary>
/// Display custom output Code
/// </Summary>
/// <Param name = "mypage"> </param>
/// <Param name = "strcode"> </param>
Public static void showjs (system. Web. UI. Page mypage, string strcode)
{
Stringbuilder sb = new stringbuilder ();
SB. append ("<script language = \" javascript \ "> \ n ");
SB. append (strcode. Trim ());
SB. append ("</SCRIPT> ");
Mypage. response. Write (sb. tostring ());  
}  
/// <Summary>
/// Page reload
/// </Summary>
Public static void location ()
{
Stringbuilder sb = new stringbuilder ();
SB. append ("<script language = \" javascript \ "> \ n ");
SB. append ("window. Location. href = Window. Location. href ;");
SB. append ("</SCRIPT> ");
System. Web. httpcontext. Current. response. Write (sb. tostring ());

}  
/// <Summary>
/// Display a pop-up window
/// </Summary>
/// <Param name = "str"> </param>
Public static void show (string Str)
{
Stringbuilder sb = new stringbuilder ();
SB. append ("<script language = \" javascript \ "> \ n ");
SB. append ("alert (\" "+ Str. Trim () +" \ "); \ n ");
SB. append ("</SCRIPT> ");

System. Web. httpcontext. Current. response. Write (sb. tostring ());

/// <Summary>
/// Display a pop-up window and close the current page
/// </Summary>
/// <Param name = "str"> </param>
Public static void showclose (string Str)
{
System. Text. stringbuilder sb = new system. Text. stringbuilder ();
SB. append ("<script language = \" javascript \ "> \ n ");
SB. append ("alert (\" "+ Str. Trim () +" \ "); \ n ");
SB. append ("window. Close (); \ n ");
SB. append ("</SCRIPT> \ n ");
System. Web. httpcontext. Current. response. Write (sb. tostring ());
}  
/// <Summary>
/// Display a pop-up window and switch to the current page (refresh)
/// </Summary>
/// <Param name = "str"> </param>
Public static void showlocation (string Str)
{
Stringbuilder sb = new stringbuilder ();
SB. append ("<script language = \" javascript \ "> \ n ");
SB. append ("alert (\" "+ Str. Trim () +" \ "); \ n ");
SB. append ("window. Location. href = Window. Location. href; \ n ");
SB. append ("</SCRIPT> ");

System. Web. httpcontext. Current. response. Write (sb. tostring ());
}  
/// <Summary>
/// Display a pop-up window and navigate to the target page (navigation)
/// </Summary>
/// <Param name = "str"> </param>
/// <Param name = "url"> </param>
Public static void showredirect (string STR, string URL)
{
Stringbuilder sb = new stringbuilder ();
SB. append ("<script language = \" javascript \ "> \ n ");
SB. append ("alert (\" "+ Str. Trim () +" \ "); \ n ");
SB. append ("window. Location. href = \" "+ URL. Trim () +" \ "; \ n ");
SB. append ("</SCRIPT> ");

System. Web. httpcontext. Current. response. Write (sb. tostring ());
}  
/// <Summary>
/// Display a pop-up window and move to the previous page
/// </Summary>
/// <Param name = "str"> </param>
Public static void showpre (string Str)
{
Stringbuilder sb = new stringbuilder ();
SB. append ("<script language = \" javascript \ "> \ n ");
SB. append ("alert (\" "+ Str. Trim () +" \ "); \ n ");
SB. append ("Var P = Document. referrer; \ n ");
SB. append ("window. Location. href = P; \ n ");
SB. append ("</SCRIPT> ");

System. Web. httpcontext. Current. response. Write (sb. tostring ());
}  
/// <Summary>
/// Redirect
/// </Summary>
/// <Param name = "url"> </param>
Public static void redirectpage (string URL)
{
String Path = "http: //" + system. Web. httpcontext. Current. Request. url. Host + URL;
Stringbuilder sb = new stringbuilder ();
SB. append ("<script language = \" javascript \ "> \ n ");
SB. append (string. Format ("window. Location. href = '{0}';", @ path ));
SB. append ("</SCRIPT> ");

System. Web. httpcontext. Current. response. Write (sb. tostring ());
}

 
}
}

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.