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

Posted on 2006-05-11
Last Modified: 2008-02-01

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
Question by:ottenm
    LVL 6

    Accepted 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
    LVL 6

    Expert Comment

    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

    Author Comment

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    759 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

    9 Experts available now in Live!

    Get 1:1 Help Now