ASP. NET opens a new page without closing the original page instance code
- 2020-06-23 00:07:56
- OfStack
Respose.Write("<script language='javascript'>window.open('"+ url +"');</script>"); (Open the 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 the original window is replaced;
2. Response.Write(" < script > window.open('XXX.aspx','_blank') < /script > ") -- Keep the original window and add a new page;
3. Response.Write(" < script > window.location='XXX.aspx' < /script > ") -- Open a new page, the original window will be replaced;
4. Server. Transfer(" ES28en. aspx") -- open a new page;
5. Response.Write(" < script > window.showModelessDialog('XXX.aspx') < /script > ") -- Keep the original window and open the new window in the form of dialog box;
6. Response.Write(" < script > window.showModelDialog('XXX.aspx') < /script > ") -- Open a new window in the form of dialog box, and the original window will be replaced;
You can also write your own method:
public static void ShowMessage(System.Web.UI.Page page, string msg)
{
page.ClientScript.RegisterClientScriptBlock(page.GetType(), "a", "alert('" + msg.ToString() + "');", true);
}
When called:
ShowMessage(this," Message to display ");
Below is the code for the entire class that you can pick and choose
using System;
using System.Collections.Generic;
using System.Text;
namespace WorkLogic
{
/// <summary>
/// Displays the message prompt dialog box.
/// </summary>
public class MessageBox
{
private MessageBox()
{
}
/// <summary>
/// Displays the message prompt dialog box
/// </summary>
/// <param name="page"> Current page pointer, 1 As for the this</param>
/// <param name="msg"> Prompt information </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>
/// Click on the control Message confirmation prompt box
/// </summary>
/// <param name="page"> Current page pointer, 1 As for the this</param>
/// <param name="msg"> Prompt information </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, 1 As for the this</param>
/// <param name="msg"> Prompt information </param>
/// <param name="url"> Jump 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, 1 As for the this</param>
/// <param name="script"> The 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, 1 As for the this</param>
/// <param name="msg"> Prompt information </param>
/// <param name="url"> Jump 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());
}
}
}