The following class is found on the network because it often involves writing JS pop-up warning dialog boxes when writing background programs:
/####################################### #####
Copyright:
The content of this article is edited on this site. You can reprint, publish, and use it as needed. However, please note the original source and this statement in plain text.
Http://www.opent.cnAuthor: langtaosha
######################################## ####/
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 a 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 ());
}
}
}