Show Alert Box and then Redirect

Discussion in 'ASP .Net' started by Kuldeep, Oct 31, 2007.

  1. Kuldeep

    Kuldeep Guest

    Framework: Visual Studio 2005
    Technology: ASP.NET 2.0
    Language: C#.NET 2.0

    Hi All,

    I have an event procedure as shown below.

    protected void lnkBtSendEmail_Click(object sender, EventArgs e)

    {

    FillVariables();

    GenerateDataShuttle();

    ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script
    language='JavaScript'>alert(ABCDEFGH');</script>");

    Response.Redirect("Default.aspx");

    }

    This piece of code will not allow the Javascript function to show the
    "Alert" box to pop-up. The reason being, there is a Response.Redirect
    happening soon after the ClientScript.RegisterStartupScript.

    Now, if I comment the Response.Redirect line, the alert box pops up and
    shows up the message (ABCDEFGH).

    How do I show the Alert Box first and then redirect to any page?

    Thanks in advance,

    Kuldeep
     
    Kuldeep, Oct 31, 2007
    #1
    1. Advertisements

  2. Kuldeep

    Aidy Guest

    You need to do the redirect in your javascript also.

    alert ('ABCDEFGH'); window.location.href = 'newpage.aspx';
     
    Aidy, Oct 31, 2007
    #2
    1. Advertisements

  3. Kuldeep

    Kuldeep Guest

    ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script
    language='JavaScript'>alert('ABCDEFGH'); window.location.href =
    'Default.aspx';</script>");

    Oops that should work!
     
    Kuldeep, Oct 31, 2007
    #3
  4. ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp",
    "alert('ABCDEFGH'); window.location.href = 'Default.aspx';", true);

    Then you don't need to worry about using deprecated <script> tags...
     
    Mark Rae [MVP], Oct 31, 2007
    #4
  5. Kuldeep

    Tmkasp

    Joined:
    Mar 21, 2009
    Messages:
    1
    Likes Received:
    0
    thanks dude

    As i am a beginner, u saved my time lot.. Thanks..
     
    Tmkasp, Mar 21, 2009
    #5
  6. Kuldeep

    sun_kkd

    Joined:
    Apr 27, 2012
    Messages:
    1
    Likes Received:
    0
    The redirect is slow and takes a minute. Is there a way to load the redirect faster.
     
    sun_kkd, Apr 27, 2012
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.