How To: Popup Confirmation Dialog & Redirect in LinkButton_OnClick

  • Thread starter Thread starter steggun
  • Start date Start date
S

steggun

How To: Popup Confirmation Dialog & Redirect in LinkButton_OnClick


Hello All,
I have a ASP.NET 2.0 (C#) web form with a LinkButton control. In the
server-side code for the LinkButton_OnClick event, I need to do some
processing and, if it succeeds, popup a confirmation dialog and redirect to
a different page. How can I do this?

Here's some pseudo-code:

LinkButton_OnClick()
{
// Process code
// Check for success
if (success)
{
// Popup confirmation dialog stating that the process succeeded
// [user clicks Ok on the dialog]
Response.Redirect("nextpage.aspx", true);
}
else
{
// Handle
}
}

Thanks!
 
Steggun,
You cannot do this in a server side codebehind event handler as the page has
already posted back and is running back through IIS on the server. There are
workarounds however.
You could either use some client-side javascript to handle the onclick event
and popup a window with a quasi-confirm in it, capture the
window.returnValue, and then perform a conditional redirect by setting the
window.location.href of the parent page to the new page.

Or, you could just have the server side code do a server.Transfer to an
interstitial confirmation page that uses the META refresh construct to have a
timed reload but with the target being the final page.

Just some ideas.
Peter
 
Back
Top