In general, response. the redirect method is switched on the server side, so unless response. write ("<SCRIPT> window. location = 'HTTP: // DOTNET. aspx. CC '; </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 a new window. The following two methods can be used.
Method 1: set the target attribute on the server. This method is also very suitable when the client does not support scripts.CodeAs follows:
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)
{
Form1.target= "_ Blank";
}
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 >
Method 2: Use a client script to set the target attribute. The Code is as follows: 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 >
The target attribute in the above two methods can use any valid name, but note that if the window with the same name already opens, the new window will open in the window with the same name already exists.