Asp.net Response. Redirect Method of jumping out of framework and opening window

Source: Internet
Author: User

Asp tutorial. net Response. Redirect jump out of framework and window opening method

Js top. location is probably used to jump out of the framework.

Response. Write ('<script> top. location = 'http: // www.111cn.net'; </script> ');


Response. the Redirect Method is switched on the server side, so unless Response. write ("<script> window. location = 'URL'; </script> ") the specified url address cannot be opened in a new window. However, if you carefully analyze it and set the target attribute of the form element, you can still open the new window

<% @ Page Language = "C #" AutoEventWireup = "true" %>

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>

<Script runat = "server">

Protected void Page_Load (object sender, EventArgs e)
    {
Button1.Attributes. Add ("onclick", "this.form.tar get = '_ newname '");
    }

Protected void button#click (object sender, EventArgs e)
    {
Response. Redirect ("http://dotnet.aspx.cc ");
    }
</Script>

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<Title> </title>
</Head>
<Body id = "B" runat = "server">
<Form id = "form1" runat = "server">
<Asp: Button ID = "Button1" runat = "server" OnClick = "button#click" Text = "open a new window or new Tab"/>
</Form>
</Body>
</Html>

To set the width and height of the pop-up window, you can change it to the following method:

<% @ Page Language = "C #" AutoEventWireup = "true" %>

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>

<Script runat = "server">

Protected void Page_Load (object sender, EventArgs e)
    {
String WindowName = "win" + System. DateTime. Now. Ticks. ToString ();
Page. RegisterOnSubmitStatement ("js", "window. open ('', '"+ WindowName +"', 'width = 600, height = 200 ')");
Form1.Target = WindowName;
    }

Protected void button#click (object sender, EventArgs e)
    {
Response. Redirect ("http://www.111cn.net ");
    }
</Script>

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<Title> </title>
</Head>
<Body id = "B" runat = "server">
<Form id = "form1" runat = "server">
<Asp: Button ID = "Button1" runat = "server" OnClick = "button#click" Text = "open a new window or new Tab"/>
</Form>
</Body>
</Html>

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.