In the WinForm background, we MessageBox.Show ("message") way to return to the background information, in the WebForm background, we through the Response.Write ("message") to return to the background message, However, it is necessary to display the message value as a string to the foreground page, and whether there is a popup message similar to MessageBox.Show ("message"). We will soon think of JavaScript's alert method. The call to alert is implemented by invoking JS in the background. Usage: Response.Write ("<script>alert ('" +value+ ") </script>"); Of course, during the development of the ASP, we often need to give the user prompt information, such as whether "Operation succeeded", "OK" or "Cancel" operation. (1) Click the button on the page, pop up a dialog box prompt is "OK" or "Cancel" operation, we use the button to add properties to complete: example: Public System.Web.UI.WebControls.Button btndelrow; BTNDELROW.ATTRIBUTES.ADD ("onclick", "return confirm (' OK to delete? ');"); (2) Click on the link on the page, pop up a dialog box prompt is "OK" or "Cancel" action, in the Page_Load () event, you want to give a confirmation prompt for the button to increase the properties: Example: Link.Attributes.Add ("onclick", "return Co Nfirm (' Do you want to perform this operation? ‘);");
(3) for the page to complete an action, a popup dialog box prompts whether "Operation succeeded". Example: Response.Write ("<script>...alert (' delete succeeded! ') </script> ");
(4) allow the ASP. NET server control to issue a client script block in Page: public virtual void RegisterStartupScript (string key,string script); Example: if (!this. isstartupscriptregistered ("Hello")) this. RegisterStartupScript ("Hello", "<script>...alert" (' Hello! ') </script> ");
The OK dialog box pops up: Response.Write ("<script language=javascript>...alert (' Message! ');</script> ");
Popup "OK" dialog box, click after Jump page: Response.Write ("<script language=javascript>...alert (' Message! '); Window.navigate ('. /index.aspx ');</script> ");
Pop up the OK and Cancel dialog boxes and click OK to do the following: Method one: In the Page_Load event, write button1.attributes["OnClick"]= "Javascript:return confirm (' Are you sure you want to delete it? '), and then write your execution code in the Button1_onclick event. Method Two: Write Response.Write directly in the Button1_onclik event ("<script language=javascript>...if (' Are you sure you want to delete it?") ‘))... {window.navigate (' dodelete.aspx ');} </Script> "); Method two need to jump to another page to perform operations, a little more cumbersome than the method, but how to use to see the specific situation.
Collected. Appliance class
Using System;
<summary>//Alert Summary description. </summary>
public class Alert {public static void Showalert (String message)
{
if (message==null)
message = ""; LJJ//2005-12-9
Message=message. Replace ("", "" ");
System.Web.HttpContext.Current.Response.Write ("<script>...alert ('" +message+ "');</script>");
}
public static void Showalert (String message,string URL) {
if (message==null)
message = "";
Message = message. Replace ("", "" ");
System.Web.HttpContext.Current.Response.Write ("<script>...alert" ("+message+"); location= ' "+url+"; </ Script> ");
}
public static void Showconfirmalert (String message, String Confirmurl, String cancelurl)
... {
if (message = = NULL)
message = "";
Message = message. Replace ("", "" ");
System.Web.HttpContext.Current.Response.Write ("<script language=javascript>if (' Confirm (' + message + ') ') { Document.location.href= ' + Confirmurl + ';}
else {
document.location.href= ' "+ Cancelurl +" '}</script> ");
}
public static void Showconfirmalert (String message, String confirmurl)
... {
if (message = = NULL)
message = "";
Message = message. Replace ("", "" ");
System.Web.HttpContext.Current.Response.Write ("<script language=javascript>if (" Confirm (' + message + '))
{document.location.href= ' + Confirmurl + ';} else {window.history.back ();} </script> ");
}
public static void Redirect (string url)
... {////if (url==null| | Url. LENGTH<1)
Showalert ("redirect address cannot be empty");
Else
System.Web.HttpContext.Current.Response.Write ("<script>location=" "+url+" ';</script> ");
}
public static void Ssologinredirect (string url)
{
Redirect (URL); //
if (url==null| | Url. LENGTH<1)//
Showalert ("redirect address cannot be empty"); //
else//
System.Web.HttpContext.Current.Response.Write ("<script>if (Window.parent!=window) window.parent.location= window.location; Location= ' "+url+" ';</script> "); }
public static void Showalert (String message,string url,bool isredirect)
{
if (message==null)
message = "";
if (Isredirect)
Showalert (Message,url);
Else
Showalert (message); }
}
ASP. The way to pop up the message dialog box! "Go"