468,532 Members | 1,653 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,532 developers. It's quick & easy.

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 3361
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by lukeo | last post: by
2 posts views Thread by Todd Lu | last post: by
reply views Thread by Nazir | last post: by
2 posts views Thread by news://news.microsoft.com/microsoft.public.de.germ | last post: by
4 posts views Thread by Hitesh | last post: by
5 posts views Thread by Doug | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.