Asp.net dialog box (output alet warning box)
Last Update:2018-12-08
Source: Internet
Author: User
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 ());
}
}
}