Get the App
SLTechnology News&Howtos  ›  Development  › 

How to enable ASP.NET to open a new page without closing the original page

Shulou Source: shulou.com Published: 2022-06-03 06:57:14 10月03日 Update

This article focuses on "how to achieve ASP.NET to open a new page without closing the original page", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "how to enable ASP.NET to open a new page without closing the original page"!

The copy code is as follows:

Respose.Write ("window.open ('" + url + ");"); (open a concise window):

Respose.Write ("window.open ('" + url + ", 'resizable=1,scrollbars=0,status=1,menubar=no,toolbar=no,location=no, menu=no');")

1. Response.Redirect ("XXX.aspx", true)-go directly to the new page and the original window is replaced

2. Response.Write ("window.open ('XXX.aspx','_blank')")-keep the original window and add a new page

3. Response.Write ("_ window.location='XXX.aspx'")-opens a new page and the original window is replaced

4. Server.Transfer ("XXX.aspx")-- Open a new page

5. Response.Write ("window.showModelessDialog ('XXX.aspx')")-keep the original window and open a new window as a dialog box

6. Response.Write ("window.showModelDialog ('XXX.aspx')")-opens a new window in the form of a dialog box, and the original window is replaced

You can also write your own method:

The copy code is as follows:

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")

Here is the code for the whole class that you can pick and use.

The copy code is as follows:

Using System

Using System.Collections.Generic

Using System.Text

Namespace WorkLogic

{

/ / /

/ / displays the message prompt dialog box.

/ / /

Public class MessageBox

{

Private MessageBox ()

{

}

/ / /

/ / display message prompt dialog box

/ / /

/ / current page pointer, usually this

/ / prompt information

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)

}

/ / /

/ / Control Click message confirmation prompt box

/ / /

/ / current page pointer, usually this

/ / prompt information

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 + "');")

}

/ / /

/ / display the message prompt dialog box and jump to the page

/ / /

/ / current page pointer, usually this

/ / prompt information

/ / the target URL of the jump

Public static void ShowAndRedirect (System.Web.UI.Page page, string msg, string url, string frame)

{

StringBuilder Builder = new StringBuilder ()

Builder.Append ("")

Builder.AppendFormat ("alert ('{0}');", msg)

Builder.AppendFormat ("top." + frame + ".location.href ='{0}'", url)

Builder.Append ("")

Page.ClientScript.RegisterStartupScript (page.GetType (), "message", Builder.ToString ())

}

/ / /

/ / output custom script information

/ / /

/ / current page pointer, usually this

/ / output script

Public static void ResponseScript (System.Web.UI.Page page, string script)

{

Page.ClientScript.RegisterStartupScript (page.GetType (), "message", "" + script + "")

}

/ / /

/ / display the message prompt dialog box and jump to the page

/ / current page pointer, usually this

/ / prompt information

/ / the target URL of the jump

Public static void ShowAndRedirect (System.Web.UI.Page page, string msg, string url)

{

StringBuilder Builder = new StringBuilder ()

Builder.Append ("")

Builder.AppendFormat ("alert ('{0}');", msg)

Builder.AppendFormat ("top.location.href=' {0}'", url)

Builder.Append ("")

Page.ClientScript.RegisterStartupScript (page.GetType (), "message", Builder.ToString ())

}

}

}

At this point, I believe you have a deeper understanding of "how to achieve ASP.NET to open a new page without closing the original page". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Pages hints code dialogs messages conversations information pointers content forms methods goals scripts learning output practical deeper concise interesting practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno macOS Apple Shulou Technology