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

Replace Control Value Before Inserting

This example shows how to change the value of a control before the Insert and Update operation. In this case, we have a Record form called Tasks which has two hidden fields called LastUpdateDate and LastUpdateUserid. This fields will store the current date and ID of the user who performs the operation.

  1. Add the custom LastUpdateInfo() function.
  2. Add the Before Insert and Before Update events for the Tasks Grid.
  3. Call the LastUpdateInfo() function in both of the events.

ASP

Function LastUpdateInfo()

  Tasks.LastUpdateDate.Value = Now()
  Tasks.LastUpdateUserid.Value = CCGetUserID()

End function

Function Tasks_BeforeInsert()
  LastUpdateInfo()
End Function

Function Tasks_BeforeUpdate()
  LastUpdateInfo()
End Function

PHP

function LastUpdateInfo(){
global $Tasks;

  $Tasks->LastUpdateDate->SetValue(date("m.d.y"));
  $Tasks->LastUpdateUserid->SetValue(CCGetUserID());

}

function Tasks_BeforeInsert() {
  LastUpdateInfo();
}

function Tasks_BeforeUpdate() {
  LastUpdateInfo();
}

Perl

sub LastUpdateInfo(){

  $Tasks->{LastUpdateDate}->SetValue(time());
  $Tasks->{LastUpdateUserid}->SetValue(CCGetUserID());

}
sub Tasks_BeforeInsert() {
  LastUpdateInfo();
}

sub Tasks_BeforeUpdate() {
  LastUpdateInfo();
}

ColdFusion

<!---Tasks_BeforeInsert --->

  <CFSET fldLastUpdateDate=Now()>
  <CFSET fldLastUpdateUserid=Session.UserID>
  
<!---Tasks_BeforeUpdate --->

  <CFSET fldLastUpdateDate=Now()>
  <CFSET fldLastUpdateUserid=Session.UserID>

Java

class LUI {
  public void lastUpdateInfo(Page page) {
    page.getRecord("Tasks").getControl("LastUpdateDate").setValue(new Date());
    page.getRecord("Tasks").getControl("LastUpdateUserid").setValue(Utils.getUserId(page));
  }
}
//Tasks_BeforeInsert

  new LUI().lastUpdateInfo(e.getPage());

//Tasks_BeforeUpdate

  new LUI().lastUpdateInfo(e.getPage());

VB.Net

Function LastUpdateInfo()
  TasksLastUpdateDate.Text = DateTime.Now.ToString()
  TasksLastUpdateUserid.Value = DBUtility.UserId.ToString()
End function
'Tasks_BeforeInsert code
  LastUpdateInfo()
'Tasks_BeforeUpdate code
  LastUpdateInfo()

C#

void LastUpdateInfo()
{
  TasksLastUpdateDate.Text = DateTime.Now.ToString();
  TasksLastUpdateUserid.Value = DBUtility.UserId.ToString();
}
\\Tasks_BeforeInsert code
 LastUpdateInfo();
\\Tasks_BeforeUpdate code
 LastUpdateInfo();

See also:

Before Insert event, Before Update event


On-line, printable versions and updates