• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 517
  • Last Modified:

write to response stream *after* response.redirect? (redirect PLUS modal dialog)


I'm trying to redirect a response AND popup a dialog explaining why.

Here's the code I've been using to popup messages, but I am not having any luck putting it before or after the Response.Redirect:

  System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
  System.Web.HttpContext.Current.Response.Write("alert(""" & MessageHere & """)" & vbCrLf)

Any help greatly appreciated-

VB.NET 1.1
  • 2
1 Solution
Response.Redirect is performed on the server thus you must decide if you want to display message before last postback on original page or on load event in new page. You can do e.g. this:

Original page:
       Session("redirecting") = True

New page:
       If not Page.IsPostBack Then
         If Session("redirecting") = True then
            System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
            System.Web.HttpContext.Current.Response.Write("alert(""" & MessageHere & """)" & vbCrLf)
         End If
        End If
Another solution. Insead of response.redirect on original page use this code:

            Dim scriptString As String = "<script language=JavaScript>alert('message'); window.location='secondpage.aspx';"
            scriptString += "<"
            scriptString += "/"
            scriptString += "script>"
            If (Not IsClientScriptBlockRegistered("clientScript")) Then
                RegisterClientScriptBlock("clientScript", scriptString)
            End If
ottenmAuthor Commented:
Thanks the_paab!  

I just put the message string in the session, check for it on load, then display it and set it back to nothing.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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