Asp. NET opens a new page without closing the original page instance code

Source: Internet
Author: User
Tags reserved
This article describes the ASP.net open a new page without closing the original page instance code, the need for friends can refer to, I hope you have some help copy code code as follows:


respose.write ("<script language= ' JavaScript ' >window.open (' + URL + ');</script>"); (Open simple window):


respose.write ("<script language= ' JavaScript ' >window.open" + URL + "', ', ', ' RESIZABLE=1,SCR Ollbars=0,status=1,menubar=no,toolbar=no,location=no, Menu=no ');</script> ");


1. Response.Redirect ("xxx.aspx", true)--directly to the new page, the original window is replaced;
2. Response.Write ("<script>window.open" (' xxx.aspx ', ' _blank ') </script> ")--the original window is reserved, another new page is added;
3. Response.Write ("<script>window.location= ' xxx.aspx ' </script>")--Opens the new page, replaces the original window;
4. Server.Transfer ("xxx.aspx")--open a new page;
5. Response.Write ("<script>window.showmodelessdialog (' xxx.aspx ') </script>")--the original window is reserved to open a new window in the form of a dialog box;
6. Response.Write ("<script>window.showmodeldialog (' xxx.aspx ') </script>")--dialog form opens a new window, the original window is replaced;
You can also write your own method:

Copy Code code as follows:


public static void ShowMessage (System.Web.UI.Page Page, string msg)


{


page. Clientscript.registerclientscriptblock (page. GetType (), "a", "alert ('" + MSG.) ToString () + "');", true);


}


The time of the call:
ShowMessage (This, "message to display");
Here's the whole class code you can pick with

Copy Code code as follows:




Using System;


using System.Collections.Generic;


using System.Text;


namespace Worklogic


{


///&lt;summary&gt;


///Displays the message prompt dialog box.


///&lt;/summary&gt;


public class MessageBox


    {


private MessageBox ()


        {


        }


///&lt;summary&gt;


///Displays the message prompt dialog box


///&lt;/summary&gt;


///&lt;param name= "page" &gt; current page pointer, generally this&lt;/param&gt;


&lt;param name= "MSG" &gt; Hint info &lt;/param&gt;


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


        }


///&lt;summary&gt;


///Control Click the Message confirmation prompt box


///&lt;/summary&gt;


///&lt;param name= "page" &gt; current page pointer, generally this&lt;/param&gt;


///&lt;param name= "MSG" &gt; Hint info &lt;/param&gt;


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


        }


///&lt;summary&gt;


///Displays the message prompt dialog box and makes a page jump


///&lt;/summary&gt;


///&lt;param name= "page" &gt; current page pointer, generally this&lt;/param&gt;


///&lt;param name= "MSG" &gt; Hint info &lt;/param&gt;


///&lt;param name= "url" &gt; Jump target url&lt;/param&gt;


public static void Showandredirect (System.Web.UI.Page Page, String msg, string URL, string frame)


        {


StringBuilder Builder = new StringBuilder ();


builder.append ("&lt;script language= ' JavaScript ' defer&gt;");


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


Builder.appendformat ("top." + Frame + ". Location.href= ' {0} '", URL);


builder.append ("&lt;/script&gt;");


Page. Clientscript.registerstartupscript (page. GetType (), "message", builder.tostring ());


        }


///&lt;summary&gt;


///Output Custom script information


///&lt;/summary&gt;


///&lt;param name= "page" &gt; current page pointer, generally this&lt;/param&gt;


///&lt;param name= "script" &gt; Output script &lt;/param&gt;


public static void Responsescript (System.Web.UI.Page Page, string script)


        {


Page. Clientscript.registerstartupscript (page. GetType (), "message", "&lt;script language= ' JavaScript ' defer&gt;" + script + "&lt;/script&gt;");


        }


///&lt;summary&gt;


///Displays the message prompt dialog box and makes a page jump


///&lt;param name= "page" &gt; current page pointer, generally this&lt;/param&gt;


///&lt;param name= "MSG" &gt; Hint info &lt;/param&gt;


///&lt;param name= "url" &gt; Jump target url&lt;/param&gt;


public static void Showandredirect (System.Web.UI.Page Page, String msg, string URL)


        {


StringBuilder Builder = new StringBuilder ();


builder.append ("&lt;script language= ' JavaScript ' defer&gt;");


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


Builder.appendformat ("top.location.href= ' {0} '", URL);


builder.append ("&lt;/script&gt;");


page. Clientscript.registerstartupscript (page. GetType (), "message", builder.tostring ());


       }


}


}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.