Respose. Write ("<script language = 'javascript '> window. open ('" + url + "'); </script>"); (open a concise window ):
Respose. write ("<script language = 'javascript '> window. open ('"+ url +"', '', 'resizable = 1, scrollbars = 0, status = 1, menubar = no, toolbar = no, location = no, menu = no'); </script> ");
1. Response. Redirect ("XXX. aspx", true) -- go directly to the new page and replace the original window;
2. response. write ("<script> window. open ('xxx. aspx ',' _ blank ') </script> ") -- the original window is retained, and a new page is added;
3. Response. Write ("<script> window. location = 'xxx. aspx '</script>") -- open a new page and replace the original window;
4. Server. Transfer ("XXX. aspx") -- open a new page;
5. Response. Write ("<script> window. showModelessDialog ('xxx. aspx ') </script>") -- retain the original window and open a new window in the form of a dialog box;
6. Response. Write ("<script> window. showModelDialog ('xxx. aspx ') </script>") -- opens a new window in the dialog box, and the original window is replaced;
You can also write the following code by yourself:
Public static void ShowMessage (System. Web. UI. Page page, string msg)
{
Page. ClientScript. RegisterClientScriptBlock (page. GetType (), "a", "alert ('" + msg. ToString () + "');", true );
}
When calling:
ShowMessage (this, "message to be displayed ");
The following is the code of the entire class that you can use.
Using System;
Using System. Collections. Generic;
Using System. Text;
Namespace WorkLogic
{
/// <Summary>
/// Display the message prompt dialog box.
/// </Summary>
Public class MessageBox
{
Private MessageBox ()
{
}
/// <Summary>
/// Display the message prompt dialog box
/// </Summary>
/// <Param name = "page"> current page pointer, which is generally this </param>
/// <Param name = "msg"> message </param>
Public static void ShowMessage (System. Web. UI. Page page, string msg)
{
// Page. RegisterStartupScript ("message", "alert ('" + msg. ToString () + "');");
Page. ClientScript. RegisterClientScriptBlock (page. GetType (), "a", "alert ('" + msg. ToString () + "');", true );
}
Public static void ShowMessage (System. Web. UI. UserControl control, string msg)
{
Control. page. clientScript. registerClientScriptBlock (control. page. getType (), "B", "alert ('" + msg. toString () + "');", true );
}
/// <Summary>
/// Control click the message confirmation prompt box
/// </Summary>
/// <Param name = "page"> current page pointer, which is generally this </param>
/// <Param name = "msg"> message </param>
Public static void ShowConfirm (System. Web. UI. WebControls. WebControl Control, string msg)
{
// Control. Attributes. Add ("onClick", "if (! Window. confirm ('"+ msg +"') {return false ;}");
Control. Attributes. Add ("onclick", "return confirm ('" + msg + "');");
}
/// <Summary>
/// Display the message prompt dialog box and jump to the page
/// </Summary>
/// <Param name = "page"> current page pointer, which is generally this </param>
/// <Param name = "msg"> message </param>
/// <Param name = "url"> Target URL </param>
Public static void ShowAndRedirect (System. Web. UI. Page page, string msg, string url, string frame)
{
StringBuilder Builder = new StringBuilder ();
Builder. Append ("<script language = 'javascript 'defer> ");
Builder. AppendFormat ("alert ('{0}');", msg );
Builder. AppendFormat ("top." + frame + ". location. href = '{0}'", url );
Builder. Append ("</script> ");
Page. ClientScript. RegisterStartupScript (page. GetType (), "message", Builder. ToString ());
}
/// <Summary>
/// Output Custom Script Information
/// </Summary>
/// <Param name = "page"> current page pointer, which is generally this </param>
/// <Param name = "script"> output script </param>
Public static void ResponseScript (System. Web. UI. Page page, string script)
{
Page. ClientScript. RegisterStartupScript (page. GetType (), "message", "<script language = 'javascript 'defer>" + script + "</script> ");
}
/// <Summary>
/// Display the message prompt dialog box and jump to the page
/// <Param name = "page"> current page pointer, which is generally this </param>
/// <Param name = "msg"> message </param>
/// <Param name = "url"> Target URL </param>
Public static void ShowAndRedirect (System. Web. UI. Page page, string msg, string url)
{
StringBuilder Builder = new StringBuilder ();
Builder. Append ("<script language = 'javascript 'defer> ");
Builder. AppendFormat ("alert ('{0}');", msg );
Builder. AppendFormat ("top. location. href = '{0}'", url );
Builder. Append ("</script> ");
Page. ClientScript. RegisterStartupScript (page. GetType (), "message", Builder. ToString ());
}
}
}