Access Variables in the Data Access Layer
If your Data Access Layer customization depends on the value of a control which is not data bound, you can retrieve it with the help of the DataAccessSettings class. The DataAccessSettings class can also be used to retrieve SignedInUserId and the SignedInUserName.
- Pooja Daga, Technical Support Engineer, Iron Speed, Inc.

May 24, 2006
Iron Speed Designer V3.2

Introduction
Iron Speed Designer-generated applications maintain strict separation between the Presentation Layer (user interface) and the Data Access Layer. While code customizations are typically added to an application’s Presentation Layer code-behind files, it’s sometimes useful to add customizations in the Data Access Layer. If your Data Access Layer customization depends on the value of a control which is not data bound, you can retrieve it with the help of the DataAccessSettings class. The DataAccessSettings class can also be used to retrieve other useful information, such as the SignedInUserId and the SignedInUserName.

In the example below, the AddOrdersPage.aspx page has an ASPX text box control. The value of the text box cannot be accessed directly in the Data Access Layer, so the value is passed from the Presentation Layer to the Data Access Layer via the the SystemUtils.SetDataAccessSettingsParameterValue method.

Procedure
Step 1: Handle the PostGetUIData event in the Page class of AddOrdersPage.aspx. Use the SetDataAccessSettingsParameterValue method to pass the value of the ASPX text box.

The SetDataAccessSettingsParameterValue method has two arguments. The first argument is a key and the second argument is its value. In the code below, “MYKEY” is the key and its value is “myKeyValue”. The SetDataAccessSettingsParameterValue method can be called in any event or method and, in this example, is called in the PostGetUIData event in the AddOrdersPage class.

The DataAccessSettings class is used to retrieve the value of the ASPX text box in the Data Access Layer.

C#:

public AddOrdersPage()
{
    this.PreRender += new EventHandler(AddOrdersPage_PreRender);
}
private void AddOrdersPage_PreRender(object sender, System.EventArgs e)
{
    this.SystemUtils.SetDataAccessSettingsParameterValue("MYKEY", "myKeyValue");
}

Visual Basic .NET:

Private Sub AddOrdersPage_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
 
Me.SystemUtils.SetDataAccessSettingsParameterValue("MYKEY", "myKeyValue")
 
End Sub

Step 2: Add the code in the OrdersRecord.cs file.

For .NET Framework 1.1, OrdersRecord.cs is located in:

...\Application Folder\DataAccess\OrdersRecord.cs

For .NET Framework 2.0, OrdersRecord.cs is located in:

...\Application Folder\App_Code\Business Layer\OrdersRecord.cs

C#:

public OrdersRecord()
{
    this.InsertedRecord+= new
    BaseClasses.IRecordWithTriggerEvents.InsertedRecordEventHandler(O
    rdersRecord_InsertedRecord);
}
 
private void OrdersRecord_InsertedRecord(object sender,System.EventArgs e)
{
    DataAccessSettings dataAccessSettingsObj = DataAccessSettings.Current;
    if(dataAccessSettingsObj.ContainsKey("MYKEY"))
    {
            String myKey = (String)dataAccessSettingsObj["MYKEY"];
 
            //Retrieve the value of SignedInUserId and SignedInUserName
            String myUserID = dataAccessSettingsObj.SignedInUserId;
            String myUserName = dataAccessSettingsObj.SignedInUserName;
 
    /Add your Business logic
    }
}

Visual Basic .NET:

Private Sub OrdersRecord_InsertingRecord(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.InsertingRecord
 
    Dim dataAccessSettingsObj As DataAccessSettings = DataAccessSettings.Current()
    If dataAccessSettingsObj.ContainsKey("MYKEY") Then
 
    Dim myVal As String = DirectCast(dataAccessSettingsObj("MYKEY"), String)
 
    'Retrieve the value of SignedInUserId and SignedInUserName
 
    Dim myUserID As String = dataAccessSettingsObj.SignedInUserId
 
    Dim myUserName As String = dataAccessSettingsObj.SignedInUserName
 
    'Add your Business logic
 
    End If
End Sub

Note that you can retrieve the value of a control in any of the events available in the OrdersRecord.cs or vb based on where your business logic is to be added. The events available in OrdersRecord.cs or vb are:

InsertingRecord

InsertedRecord

SavingRecord

SavedRecord

DeletingRecord

DeletedRecord

UpdatedRecord

UpdatingRecord

About the Author
Pooja Daga
Technical Support Engineer, Iron Speed, Inc.

Pooja has experience developing Web applications using .NET technology. She started her career with PCS, a leading software services company headquartered in India and has been with Iron Speed since 2005.

Pooja holds an M.S. degree in Computer Application and a B.S. degree in Electrical engineering from Maharaja Sayajirao University in India.



  Privacy Statement