473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Redirect a page after a new window opened?

I am trying to do something pretty simple - but can't see how it can
be done in ASP.NET.

I have an aspx web page with a form which opens up a new window. The
web page uses code behind to build the new window. There is simple
validation on the form.

However, after the form page validates and opens the new window, I
want it to redirect to another page (or stop displaying the form).

I've tried adding code to the aspx.vb page to handle this, but it only
affects the new window, not the window with the form on. If I try and
do the redirection before IsPostBack, then it always redirects.

I've tried adding code to the forms OnSubmit javascript event in the
aspx page, but then it interferes with validation - and bypasses it.

Here is an example of what I'm trying to do:

####### aspx page

<%@ Page Language="vb" Src="NGExample.aspx.vb" Inherits="NGExample"%>

<html lang="en">
<body>
<h1>Form Window</h1>
<form id="NGExample" method="post" target="_blank" runat="server">
<asp:ValidationSummary
id="valSummary"
runat="server"
HeaderText="Sorry, there was a problem with your details:"
ShowSummary="true" DisplayMode="List" />

<p>Required field - </p>
<table border=0>
<tr><td width="120">Input name
<asp:RequiredFieldValidator id="valRequired1"
runat="server"
ControlToValidate="txtName"
ErrorMessage="* You must enter a name"
Display="static">*</asp:RequiredFieldValidator>:
</td><td>
<asp:TextBox id="txtName"
Text="The Name"
maxLength="100"
width="275px"
runat="server" /></td></tr>
</td></tr>
<tr><td colspan="2" align="right">
<asp:Button id="createNewWindow"
Text="Submit" runat="server">
</asp:Button>
</td></tr>
</table>
</form>
</body>
</html>

########## aspx.vb
Public Class NGExample
Inherits System.Web.UI.Page
Protected txtName As System.Web.UI.WebControls.TextBox

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If IsPostBack Then
Response.Write("<h1>New Window</h1>")
Response.Write("Form Field: " & txtName.Text)
Response.End()

End If
End Sub

End Class

Any help much apprecaited.

NH
Nov 17 '05 #1
5 3578
The problem is that your CodeBehind is being run in the instance of your
class that runs in the new window. You need to use
Page.RegisterStartupScript() to generate a JavaScript that uses the
window.open() method to open the new window, and then redirects to the URL
you specify.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Nazir" <na***********@yahoo.co.uk> wrote in message
news:9e*************************@posting.google.co m...
I am trying to do something pretty simple - but can't see how it can
be done in ASP.NET.

I have an aspx web page with a form which opens up a new window. The
web page uses code behind to build the new window. There is simple
validation on the form.

However, after the form page validates and opens the new window, I
want it to redirect to another page (or stop displaying the form).

I've tried adding code to the aspx.vb page to handle this, but it only
affects the new window, not the window with the form on. If I try and
do the redirection before IsPostBack, then it always redirects.

I've tried adding code to the forms OnSubmit javascript event in the
aspx page, but then it interferes with validation - and bypasses it.

Here is an example of what I'm trying to do:

####### aspx page

<%@ Page Language="vb" Src="NGExample.aspx.vb" Inherits="NGExample"%>

<html lang="en">
<body>
<h1>Form Window</h1>
<form id="NGExample" method="post" target="_blank" runat="server">
<asp:ValidationSummary
id="valSummary"
runat="server"
HeaderText="Sorry, there was a problem with your details:"
ShowSummary="true" DisplayMode="List" />

<p>Required field - </p>
<table border=0>
<tr><td width="120">Input name
<asp:RequiredFieldValidator id="valRequired1"
runat="server"
ControlToValidate="txtName"
ErrorMessage="* You must enter a name"
Display="static">*</asp:RequiredFieldValidator>:
</td><td>
<asp:TextBox id="txtName"
Text="The Name"
maxLength="100"
width="275px"
runat="server" /></td></tr>
</td></tr>
<tr><td colspan="2" align="right">
<asp:Button id="createNewWindow"
Text="Submit" runat="server">
</asp:Button>
</td></tr>
</table>
</form>
</body>
</html>

########## aspx.vb
Public Class NGExample
Inherits System.Web.UI.Page
Protected txtName As System.Web.UI.WebControls.TextBox

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If IsPostBack Then
Response.Write("<h1>New Window</h1>")
Response.Write("Form Field: " & txtName.Text)
Response.End()

End If
End Sub

End Class

Any help much apprecaited.

NH

Nov 17 '05 #2
The problem is that your CodeBehind is being run in the instance of your
class that runs in the new window. You need to use
Page.RegisterStartupScript() to generate a JavaScript that uses the
window.open() method to open the new window, and then redirects to the URL
you specify.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Nazir" <na***********@yahoo.co.uk> wrote in message
news:9e*************************@posting.google.co m...
I am trying to do something pretty simple - but can't see how it can
be done in ASP.NET.

I have an aspx web page with a form which opens up a new window. The
web page uses code behind to build the new window. There is simple
validation on the form.

However, after the form page validates and opens the new window, I
want it to redirect to another page (or stop displaying the form).

I've tried adding code to the aspx.vb page to handle this, but it only
affects the new window, not the window with the form on. If I try and
do the redirection before IsPostBack, then it always redirects.

I've tried adding code to the forms OnSubmit javascript event in the
aspx page, but then it interferes with validation - and bypasses it.

Here is an example of what I'm trying to do:

####### aspx page

<%@ Page Language="vb" Src="NGExample.aspx.vb" Inherits="NGExample"%>

<html lang="en">
<body>
<h1>Form Window</h1>
<form id="NGExample" method="post" target="_blank" runat="server">
<asp:ValidationSummary
id="valSummary"
runat="server"
HeaderText="Sorry, there was a problem with your details:"
ShowSummary="true" DisplayMode="List" />

<p>Required field - </p>
<table border=0>
<tr><td width="120">Input name
<asp:RequiredFieldValidator id="valRequired1"
runat="server"
ControlToValidate="txtName"
ErrorMessage="* You must enter a name"
Display="static">*</asp:RequiredFieldValidator>:
</td><td>
<asp:TextBox id="txtName"
Text="The Name"
maxLength="100"
width="275px"
runat="server" /></td></tr>
</td></tr>
<tr><td colspan="2" align="right">
<asp:Button id="createNewWindow"
Text="Submit" runat="server">
</asp:Button>
</td></tr>
</table>
</form>
</body>
</html>

########## aspx.vb
Public Class NGExample
Inherits System.Web.UI.Page
Protected txtName As System.Web.UI.WebControls.TextBox

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If IsPostBack Then
Response.Write("<h1>New Window</h1>")
Response.Write("Form Field: " & txtName.Text)
Response.End()

End If
End Sub

End Class

Any help much apprecaited.

NH

Nov 17 '05 #3
Dear Nazir;

One solusion is to use HTML Control instead of Server Control and use both
"onClick" and "onServerClick" events, as I did (following code).
But i think there should be better way... anybody has idea?

Regards,
Tohid
<%@ Page Language="VB" %>
<script runat="server">

Sub Button1_Click(sender As Object, e As EventArgs)
Response.Redirect("http://www.google.com")
End Sub

</script>
<html>
<head>
<script language="JavaScript">
function OpenNew() {
window.open("http://www.yahoo.com")
}
</script>
</head>
<body>
<form runat="server">
<input id="button1" onclick="javascript:OpenNew();" type="button"
value="Button" runat="server" onserverclick="Button1_Click" />
<!-- Insert content here -->
</form>
</body>
</html>


----- Original Message -----
From: "Nazir" <na***********@yahoo.co.uk>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, October 22, 2003 1:21 PM
Subject: Redirect a page after a new window opened?

I am trying to do something pretty simple - but can't see how it can
be done in ASP.NET.

I have an aspx web page with a form which opens up a new window. The
web page uses code behind to build the new window. There is simple
validation on the form.

However, after the form page validates and opens the new window, I
want it to redirect to another page (or stop displaying the form).

I've tried adding code to the aspx.vb page to handle this, but it only
affects the new window, not the window with the form on. If I try and
do the redirection before IsPostBack, then it always redirects.

I've tried adding code to the forms OnSubmit javascript event in the
aspx page, but then it interferes with validation - and bypasses it.

Here is an example of what I'm trying to do:

####### aspx page

<%@ Page Language="vb" Src="NGExample.aspx.vb" Inherits="NGExample"%>

<html lang="en">
<body>
<h1>Form Window</h1>
<form id="NGExample" method="post" target="_blank" runat="server">
<asp:ValidationSummary
id="valSummary"
runat="server"
HeaderText="Sorry, there was a problem with your details:"
ShowSummary="true" DisplayMode="List" />

<p>Required field - </p>
<table border=0>
<tr><td width="120">Input name
<asp:RequiredFieldValidator id="valRequired1"
runat="server"
ControlToValidate="txtName"
ErrorMessage="* You must enter a name"
Display="static">*</asp:RequiredFieldValidator>:
</td><td>
<asp:TextBox id="txtName"
Text="The Name"
maxLength="100"
width="275px"
runat="server" /></td></tr>
</td></tr>
<tr><td colspan="2" align="right">
<asp:Button id="createNewWindow"
Text="Submit" runat="server">
</asp:Button>
</td></tr>
</table>
</form>
</body>
</html>

########## aspx.vb
Public Class NGExample
Inherits System.Web.UI.Page
Protected txtName As System.Web.UI.WebControls.TextBox

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If IsPostBack Then
Response.Write("<h1>New Window</h1>")
Response.Write("Form Field: " & txtName.Text)
Response.End()

End If
End Sub

End Class

Any help much apprecaited.

NH

Nov 17 '05 #4
Dear Nazir;

One solusion is to use HTML Control instead of Server Control and use both
"onClick" and "onServerClick" events, as I did (following code).
But i think there should be better way... anybody has idea?

Regards,
Tohid
<%@ Page Language="VB" %>
<script runat="server">

Sub Button1_Click(sender As Object, e As EventArgs)
Response.Redirect("http://www.google.com")
End Sub

</script>
<html>
<head>
<script language="JavaScript">
function OpenNew() {
window.open("http://www.yahoo.com")
}
</script>
</head>
<body>
<form runat="server">
<input id="button1" onclick="javascript:OpenNew();" type="button"
value="Button" runat="server" onserverclick="Button1_Click" />
<!-- Insert content here -->
</form>
</body>
</html>


----- Original Message -----
From: "Nazir" <na***********@yahoo.co.uk>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, October 22, 2003 1:21 PM
Subject: Redirect a page after a new window opened?

I am trying to do something pretty simple - but can't see how it can
be done in ASP.NET.

I have an aspx web page with a form which opens up a new window. The
web page uses code behind to build the new window. There is simple
validation on the form.

However, after the form page validates and opens the new window, I
want it to redirect to another page (or stop displaying the form).

I've tried adding code to the aspx.vb page to handle this, but it only
affects the new window, not the window with the form on. If I try and
do the redirection before IsPostBack, then it always redirects.

I've tried adding code to the forms OnSubmit javascript event in the
aspx page, but then it interferes with validation - and bypasses it.

Here is an example of what I'm trying to do:

####### aspx page

<%@ Page Language="vb" Src="NGExample.aspx.vb" Inherits="NGExample"%>

<html lang="en">
<body>
<h1>Form Window</h1>
<form id="NGExample" method="post" target="_blank" runat="server">
<asp:ValidationSummary
id="valSummary"
runat="server"
HeaderText="Sorry, there was a problem with your details:"
ShowSummary="true" DisplayMode="List" />

<p>Required field - </p>
<table border=0>
<tr><td width="120">Input name
<asp:RequiredFieldValidator id="valRequired1"
runat="server"
ControlToValidate="txtName"
ErrorMessage="* You must enter a name"
Display="static">*</asp:RequiredFieldValidator>:
</td><td>
<asp:TextBox id="txtName"
Text="The Name"
maxLength="100"
width="275px"
runat="server" /></td></tr>
</td></tr>
<tr><td colspan="2" align="right">
<asp:Button id="createNewWindow"
Text="Submit" runat="server">
</asp:Button>
</td></tr>
</table>
</form>
</body>
</html>

########## aspx.vb
Public Class NGExample
Inherits System.Web.UI.Page
Protected txtName As System.Web.UI.WebControls.TextBox

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If IsPostBack Then
Response.Write("<h1>New Window</h1>")
Response.Write("Form Field: " & txtName.Text)
Response.End()

End If
End Sub

End Class

Any help much apprecaited.

NH

Nov 17 '05 #5
Thanks for the replies - they led me to an answer:

I registered an onsubmit script in the code behind page,

RegisterOnSubmitStatement("valid", " if (Page_IsValid)
{window.location = '[result url]'} ")

NH
"Tohid" <To********@hotmail.com> wrote in message news:<#8*************@TK2MSFTNGP11.phx.gbl>...
Dear Nazir;

One solusion is to use HTML Control instead of Server Control and use both
"onClick" and "onServerClick" events, as I did (following code).
But i think there should be better way... anybody has idea?

Regards,
Tohid
<%@ Page Language="VB" %>
<script runat="server">

Sub Button1_Click(sender As Object, e As EventArgs)
Response.Redirect("http://www.google.com")
End Sub

</script>
<html>
<head>
<script language="JavaScript">
function OpenNew() {
window.open("http://www.yahoo.com")
}
</script>
</head>
<body>
<form runat="server">
<input id="button1" onclick="javascript:OpenNew();" type="button"
value="Button" runat="server" onserverclick="Button1_Click" />
<!-- Insert content here -->
</form>
</body>
</html>


----- Original Message -----
From: "Nazir" <na***********@yahoo.co.uk>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, October 22, 2003 1:21 PM
Subject: Redirect a page after a new window opened?

I am trying to do something pretty simple - but can't see how it can
be done in ASP.NET.

I have an aspx web page with a form which opens up a new window. The
web page uses code behind to build the new window. There is simple
validation on the form.

However, after the form page validates and opens the new window, I
want it to redirect to another page (or stop displaying the form).

I've tried adding code to the aspx.vb page to handle this, but it only
affects the new window, not the window with the form on. If I try and
do the redirection before IsPostBack, then it always redirects.

I've tried adding code to the forms OnSubmit javascript event in the
aspx page, but then it interferes with validation - and bypasses it.

Here is an example of what I'm trying to do:

####### aspx page

<%@ Page Language="vb" Src="NGExample.aspx.vb" Inherits="NGExample"%>

<html lang="en">
<body>
<h1>Form Window</h1>
<form id="NGExample" method="post" target="_blank" runat="server">
<asp:ValidationSummary
id="valSummary"
runat="server"
HeaderText="Sorry, there was a problem with your details:"
ShowSummary="true" DisplayMode="List" />

<p>Required field - </p>
<table border=0>
<tr><td width="120">Input name
<asp:RequiredFieldValidator id="valRequired1"
runat="server"
ControlToValidate="txtName"
ErrorMessage="* You must enter a name"
Display="static">*</asp:RequiredFieldValidator>:
</td><td>
<asp:TextBox id="txtName"
Text="The Name"
maxLength="100"
width="275px"
runat="server" /></td></tr>
</td></tr>
<tr><td colspan="2" align="right">
<asp:Button id="createNewWindow"
Text="Submit" runat="server">
</asp:Button>
</td></tr>
</table>
</form>
</body>
</html>

########## aspx.vb
Public Class NGExample
Inherits System.Web.UI.Page
Protected txtName As System.Web.UI.WebControls.TextBox

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If IsPostBack Then
Response.Write("<h1>New Window</h1>")
Response.Write("Form Field: " & txtName.Text)
Response.End()

End If
End Sub

End Class

Any help much apprecaited.

NH

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lukeo | last post by:
I'm shelling out to an .asp (or htm) page from an application. I want to show this in a window without the address bar, etc... Is there a way I can redirect this page using javascript to a page...
2
by: Todd Lu | last post by:
I am trying to redirect a login page to another page after validating the username and password. I am currently trying to use javascript with the window.open command but this leaves the...
2
by: kevinm3574 | last post by:
So, I'm doing the following in a php script so that I can fire a download dialogue AND redirect the page (after clicking submit in a form). I'm doing it this way because of the problem with...
3
by: TC | last post by:
Hello, In ASP.Net via C#, but if someone can help me with a VB.Net example that's fine too, I am trying to redirect to a page that is already open. For example, when a user clicks a submit...
0
by: Nazir | last post by:
I am trying to do something pretty simple - but can't see how it can be done in ASP.NET. I have an aspx web page with a form which opens up a new window. The web page uses code behind to build...
3
by: ODB | last post by:
Okay what i need is to open af new browser windows with some link in, but i can't get the Response.Redirect to open af new window, and when i redirect to a new page in the same window and then hit...
2
by: news://news.microsoft.com/microsoft.public.de.germ | last post by:
Hallo! Ich habe ein Frameset mit 3 Frames. Im 1. Frame wird eine ASPX-Seite geöffnet. In dieser werden einige Steuerelemente angezeigt. Nun soll bei bestimmten Benutzeraktivitäten eine andere...
4
by: Hitesh | last post by:
Hi, I am having a requirement where in user can click on a link and the download popup appears and then user should be redirected to a congratulations page. We didn't bother whether the...
5
by: Doug | last post by:
In the code below, I am trying to go from one asp page to another: For Each tripToAccept As String In tripsToAccept.Split("/"c) dataManager.UpdateTripDetail("Accept", CInt(tripToAccept),...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.