Solved

Response.Redirect doesn't work anymore

Posted on 2009-04-09
3
948 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

705 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