open a new window from code behind

A

akki

i am developing a webform in which there is a preview button.On
pressing the button, I have to open a new window and display another
aspx page there.Can anyone tell me how to do it? Response.redirect
opens the new page in the same window.

Akshay
 
N

Nathan Sokalski

There is no way to make ASP.NET open a new browser window. You can, however,
include dynamically generated Javascript code to open a new window with the
desired URL. The necessary information can be passed to this window using
whatever technique you want, including querystring, Session, etc. Opening
new windows is performed by the browser, so ASP.NET has no control over it.
However, keep in mind that many browsers have pop-up blockers that may
prevent Javascript from opening this new window (it will usually inform the
user and give them the option of opening it, but it waits for the user's
confirmation, so you should tell them why the browser will be trying to open
a new window). Good Luck!
 
K

Ken Cox - Microsoft MVP

Hi Akshay,

Here's a page in ASP.NET 2.0 that shows one way to accomplish what you need.
Let us know if it helps?

Ken
Microsoft MVP [ASP.NET[

<%@ Page Language="VB" %>
<script runat="server">
Protected Sub Button1_Click _
(ByVal sender As Object, ByVal e As System.EventArgs)
ClientScript.RegisterStartupScript _
(Me.GetType, "popup", "window.open('" & _
TextBox1.Text & "','_blank','menubar=no')", True)
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Popup Demo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:textbox id="TextBox1"
runat="server">http://www.kencox.ca/</asp:textbox><br />
<asp:button id="Button1" runat="server" onclick="Button1_Click"
text="Open" />&nbsp;</div>
</form>
</body>
</html>
 
Joined
Sep 24, 2010
Messages
1
Reaction score
0
You can use ajax to display new windows it works from codebehind.
Unfortenately I can't give you a link, because I am new at this forum and can't post links, but you can send me a message and I send you a link with very good explanations how to do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top