Redirect a page after a new window opened?

  • Thread starter Thread starter Nazir
  • Start date Start date
N

Nazir

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
 
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.
 
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" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, October 22, 2003 1:21 PM
Subject: Redirect a page after a new window opened?
 
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
 
Back
Top