Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
Hi All ,

 messagebox("you are redirected to home page")
 response.redirect("home.aspx")
 

in this code Message box is not shown. it is directly load the Home page.
 

here messagebox is a function which has Alert script.
 
How to redirect home page after the messgebox??
 

 
Regards,
Pal
Posted 2-May-12 20:08pm
palraj0012.1K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

The java-script message boxes are typically hooked on page_unload event. Like the one here:
 
A Windows Form like MessageBox for ASP.NET Website[^]
 
so if you call response.redirect the page_unload event for the earlier page will not get called after calling the messagebox function and that wont work. IF you wanto do achieve this then you should do this:
 
Response.Write("<script>alert('you are redirected to home page')</script>");
Server.Transfer("home.aspx")
 
or even this will work
 
messagebox("you are redirected to home page");
Server.Transfer("home.aspx")
 
both have some minor visible difference as on when the messagebox will appear on screen.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

ScriptManager.RegisterStartupScript(this, this.GetType(), "SetMessage" + DateTime.Now, "SetMessage('','Red');alert('Alert Before Redirection');location.href='NewPage.aspx';" , true);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
Try this code :
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "InsertedMessage", "alert('you are redirected to home page');", true);
Response.Redirect("home.aspx");
  Permalink  
Comments
sachin4dotnet at 27-Nov-12 9:45am
   
not working
Member 10271561 at 26-Dec-13 0:26am
   
not working
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

It is not so complex you have many options to do that
People says that it cannot because asp throws just after response.redirect method
But Try This i done this when my code was in ASP
 

 Response.Write("<script>alert('Hemml')</script>");
               Response.Write("<script>window.location.href='ANyPage.aspx';</script>");
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

in code behind you can call javascript function
 
in code behind
 
string script = "Redirect();";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "Redirect", script, true);
 

And in javascript
 
<script type="text/javascript">
 
function Redirect()
{
alert("Message");
    window.location="http://www.newlocation.com";
}
 
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 735
1 OriginalGriff 385
2 CPallini 240
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,835
1 Sergey Alexandrovich Kryukov 5,198
2 CPallini 4,740
3 George Jonsson 3,167
4 Gihan Liyanage 2,470


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100