Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 981
  • Last Modified:

Response.Redirect doesn't work anymore

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
Christian de Bellefeuille
Asked:
Christian de Bellefeuille
  • 2
2 Solutions
 
page1985Commented:

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
 
Christian de BellefeuilleProgrammerAuthor Commented:
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
 
page1985Commented:
haha.  well, the important thing is you got it fixed.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now