Click here to Skip to main content
12,953,014 members (77,579 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 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
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 27-Nov-12 9:45am
   
not working
Member 10271561 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  
Comments
DalachhaSolanki 23-Feb-16 11:36am
   
it's work fine..
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  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,920


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2017
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