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

Change Control Value

This example shows how to change the value of a control in the Before Show event.

Method 1: Control Level

In this instance, we will change the value of a control called FirstName which is located in a form called User.

  1. Add the Before Show event to the control
  2. Within the event, add the code below:

ASP

Function User_FirstName_BeforeShow(Sender)

  User.FirstName.Value = "Bob"

End Function

PHP

function User_FirstName_BeforeShow(& $sender) {
global $User;

  $User->FirstName->SetValue("Bob");

}

Perl

sub User_FirstName_BeforeShow() {

  $User->{FirstName}->SetValue("Bob");

}

ColdFusion

<!--- Users_FirstName_BeforeShow --->

  <CFSET fldFirstName = "Bob">
  

VB.Net

'Users_FirstName_BeforeShow

  UserFirstName.Text= "Bob"

C#

//Users_FirstName_BeforeShow 

  UserFirstName.Text= "Bob";

Java

//Users_FirstName_BeforeShow 

  e.getControl().setValue("Bob");


Method 2: Form Level

In this instance, we will change the value of a Label field called Total which is located within a Grid called Orders. Unlike the first example, we will use the Before Show event of the form instead of the Before Show event of the control.
  1. Add the Before Show Row event to the Orders form
  2. Within the event, add the code below:

ASP

Function Orders_BeforeShowRow()

  Orders.Total.Value=Orders.Quantity.Value * Orders.Price.Value

End Function

PHP

function Orders_BeforeShowRow() {
global $Orders;

  $Orders->Total->SetValue( $Orders->Quantity->GetValue() * $Orders->Price->GetValue() );

}

Perl

sub Orders_BeforeShowRow() {

  $Orders->{Total}->SetValue( $Orders->{Quantity}->GetValue() * $Orders->{Price}->GetValue() );

}

ColdFusion

<!--- Orders_BeforeShow --->

  <CFSET fldTotal=fldQuantity * fldPrice>;

VB.Net

Note: Set the Data Type property to Integer or Float for the Quantity and Price Labels..

'Orders_BeforeShow 

  OrdersTotal.Text = (item.Quantity.Value * item.Price.Value).ToString()

C#

Note: Set the Data Type property to Integer or Float for the Quantity and Price Labels.

//Orders_BeforeShow

  OrdersTotal.Text = (((Int64)item.Quantity.Value) * ((Int64)item.Price.Value)).ToString();

Java

Note: Set the Data Type property to Integer or Float for the Quantity and Price Labels.

//Orders_BeforeShow


  e.getRecord().getControl("Total").setValue(e.getRecord().getControl("Quantity").getValue().longValue() * e.getRecord().getControl("Price").getValue().doubleValue() );

 

Method 3: Page Level

In the last instance, we will change the value of a Label field called CurrentUser which is owned by the page.
  1. Add the Before Show event to the page
  2. Within the event, add the code below:

ASP

Function Page_BeforeShow()

  CurrentUser.Value="Bob"

End Function

PHP

function Page_BeforeShow() {
global $CurrentUser;

  $CurrentUser->SetValue("Bob");

}

Perl

sub Page_BeforeShow() {

  $CurrentUser->SetValue("Bob");

}

ColdFusion

<!--- Page_BeforeShow --->
  <CFSET fldCurrentUser="Bob">

VB.Net

'Page_BeforeShow 

  CurrentUser.Text="Bob"

C#

//Page_BeforeShow

  CurrentUser.Text="Bob";

Java

//Page_BeforeShow

  e.getPage().getControl("CurrentUser").setValue("Bob");

See also:

BeforeShow event


On-line, printable versions and updates