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 ());
}
}
}