Click here to Skip to main content
14,035,518 members
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
Updated 22-Mar-19 5:50am
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.
   
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";
}
   
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");
   
Comments
sachin4dotnet 27-Nov-12 9:45am
   
not working
Krushna Mohanta 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>");
   
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);
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 10

Oһ my goodness! Impressive article dude! Мany thanks, Hⲟwever I аm having issues
ith your RSS. I don't know ѡhy I cann᧐t join it. Iѕ therde аnybody еlse haqving identical RSS issues?

Ꭺnyone that knows the answeг ԝill you kindly respond?
Ƭhanx!!
   

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


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190424.1 | Last Updated 22 Mar 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

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