Solved

Response.Redirect doesn't work anymore

Posted on 2009-04-09
3
912 Views
Last Modified: 2012-05-06
This problem drive me nuts.   My code was working fine yesterday, and now i get this problem.

My main application windows open a Popup window to let the user choose for a specific event.  Once the user accept, and that he entered the good authorization code for an event, the popup should close.

But right now, my "Page.Response.Redirect" in CloseWindow doesn't work anymore.  It should  work and just reload itself to fall into the PreInit.  The PreInit should see "close" as action, then close.  But nothing happen after Redirect... it doesn't reload or preinit.

Any idea?

I thought i caused this problem by adding a "virtual directory" to my application instead of having only "/", but i removed that and i still have the problem.

I've tried to put my page.response.redirect into a try-catch bloc, but it doesn't work and give me "Thread was being aborted" error, which is normal...

PLEASE, HELP!
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Request.QueryString.Get("action") <> "close" Then

            ' Reset some Session variable

            Session("EVENT_DESC") = ""

            Session("EVENT_TYPE_KEY") = -1

        End If

    End Sub
 

    Private Sub btnAccept_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAccept.Click

        ' Some code here assign nEventKey according to what's found in the database
 

        ' If we found the item in the database, we can close the window

        If nEventKey <> -1 Then

            CloseWindow()

        End If

    End Sub
 

    Private Sub CloseWindow()

        Page.Response.Redirect("ChooseEvent.aspx?action=close")

    End Sub
 

    Private Sub ChooseEvent_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit

        If Request.QueryString.Get("action") = "close" Then

            BodyTag.Attributes.Add("onload", "javascript:(window.close())")

            BodyTag.Attributes.Add("onunload", "opener.location='Calendrier.aspx';")

        End If

    End Sub

Open in new window

0
Comment
Question by:cdebel
  • 2
3 Comments
 
LVL 6

Assisted Solution

by:page1985
page1985 earned 500 total points
ID: 24109891

Try:
    Response.Redirect("ChooseEvent.aspx?action=close")

i.e. remove Page.

Also, you can try redirecting using the full URL.

And finally, what happens when your redirect is called?  Nothing at all?  An error?
0
 
LVL 10

Accepted Solution

by:
cdebel earned 0 total points
ID: 24110234
I want to hang myself!    I've just found my error after trying your suggestions.

All this code (in the preinit) is used to close the window, then reload the caller to refresh it.  And your last comment (Nothing at all?) raised me a flag.

I noticed that my popup was closed, and that studio was still running its CloseWindow()!!!  Non-sense!  usually the windows should dissappear on the page load (because of what's set in the preinit).  

Then i notice that on my popup form:
<asp:Button ID="btnAccept" runat="server" Text="Accepter" OnClientClick="window.close();" />...

it's the reason why it was closing (OnClientClick).  I don't understand what the hell it was doing there, but it was there.  Probably a test i was doing at 4:00am, and forgot to remove it!

Extremly sorry, it was my mistake.
0
 
LVL 6

Expert Comment

by:page1985
ID: 24110268
haha.  well, the important thing is you got it fixed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now