tags:

views:

37

answers:

1

How do I redirect the page once the user has seen the confirmation page?

I am using asp.net 3.5, it's not showing me a message instead it's just redirecting to the default page. I want to see the message and once the user has clicked 'ok' then it redirects to another page.

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), key, "jAlert('" + msg + "','" + title + "');", true);
Response.Redirect("default.aspx", false);
A: 

Pass the page redirect as part of the Javascript, rather than as a server-side redirect:

var redirectLocation = Page.ResolveUrl("default.aspx");
var title = "Message Title";
var message = "Detail of the message";
var scriptTemplate = "jAlert('{0}','{1}'); location.href='{2}'";

var script = string.Format(scriptTemplate, message, title, redirectLocation);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), key, script, true);

I've broken it out like that to hopefully make my answer easier to read, plus it makes for code that's easier to maintain =)

Rob
it display the message but after 1 second it redirect to the page, is there a way it can stay there till user take action (like click the ok buttong to close the message box)
Abu Hamzah
@Nisar, in which case, I guess (after a quick google) that `jAlert` is the jQuery http://plugins.jquery.com/project/jAlert plugin of the same name. I'm not familiar with this (and the jQuery site is offline) but based on http://labs.abeautifulsite.net/projects/js/jquery/alerts/demo/ there's an additional parameter that you can pass to jAlert, where you can do the `location.href` so it triggers when the button is pressed.
Rob