CodeCharge Studio All ASP PHP Perl ColdFusion Java C#.NET VB.NET

Dynamically Redirect Users to Another Page

This example shows how to redirect the user to different pages after the Insert or Update operation is performed. In this case, we have a Record form which has an Insert button named Insert1 and an update button named Update1. We add code in the On Click event of each of the buttons to perform the redirection:

Note: The Redirect variable can be modified in the onClick event of the Button only if the Return Page property of this Button is empty, otherwise Redirect will be overwritten in page's code.

  1. Add the On Click event for each of the buttons.
  2. Within the events , add the code below:

ASP

Function Form1_Insert1_OnClick(Sender) {

  Redirect = "InsertMessagePage.asp"

} 

Function Form1_Update1_OnClick(Sender) {

  Redirect = "UpdateMessagePage.asp"

}

PHP

function Form1_Insert1_OnClick(& $sender) {
global  $Redirect;

  $Redirect = "InsertMessagePage.php";

} 

function Form1_Update1_OnClick(& $sender) {
global  $Redirect;

  $Redirect = "UpdateMessagePage.php";

}

Perl

sub Form1_Insert1_OnClick() {

  $Redirect = "InsertMessagePage.php";

} 

sub Form1_Update1_OnClick() {

  $Redirect = "UpdateMessagePage.php";

}

ColdFusion

<!---Form1_Insert1_OnClick --->

  <CFSET strRedirect = "InsertMessagePage.cfm">

<!---Form1_Update1_OnClick --->

  <CFSET strRedirect = "UpdateMessagePage.cfm">

VB.Net

'Form1_Insert1_OnClick

 RedirectUrl = "InsertMessagePage.aspx"

'Form1_Update1_OnClick

 RedirectUrl = "UpdateMessagePage.aspx"

C#

//Form1_Insert1_OnClick

 RedirectUrl = "InsertMessagePage.aspx";

//Form1_Update1_OnClick

 RedirectUrl = "UpdateMessagePage.aspx";

Java

//Form1_Insert1_OnClick

  e.getPage().setRedirectString("InsertMessagePage.do");

//Form1_Update1_OnClick

  e.getPage().setRedirectString("UpdateMessagePage.do");

See also:

OnClick event, BeforeUnload event


On-line, printable versions and updates