Access ASPX Controls in Code-Behind Classes
ASPX controls can be used and are easily added to an Iron Speed Designer-generated application. Simply drag the controls from the Iron Speed Designer tool box on to a web page in your application.
- Pooja Daga, Technical Support Engineer, Iron Speed, Inc.

May 10, 2006
Iron Speed Designer V3.2

Introduction
Controls generated by Iron Speed Designer are "data bound" controls and must be bound to database fields because they generally display data from database fields. Sometimes, however, you just want to display text on a page, place a label adjacent to a textbox or display other data that is not necessarily coming from a database field. In such cases regular ASPX controls can be used and are easily added to an Iron Speed Designer-generated application by dragging them from the Iron Speed Designer tool box on to a web page in your application.
Adding ASPX Controls to an HTML Layout Page
Follow these steps to access ASPX controls in code-behind classes generated by Iron Speed Designer.

Step 1: Create an application using a table, such as the Orders table in Northwind.

Step 2: Drag and drop an ASPX textbox on the ShowOrdersTablePage from the Iron Speed Designer tool box. In this example, the ASPX text box is not within the Table control. Iron Speed Designer adds this HTML to the HTML layout page.

<asp:textbox id="myTextbox" runat="server" /></td>

Step 3: For .NET Framework 1.1, add this code in the "Page" class of ShowOrdersTablePage.aspx.cs

C#:

Public System.Web.UI.WebControls.TextBox myTextbox;

Visual Basic .NET:

Public myTextbox As System.Web.UI.WebControls.TextBox

No extra code is required for .NET Framework 2.0 applications.

Step 4: Handle the PreRender event for the ShowOrdersTablePage and set the text of the ASPX text box. This is described in detail in the following sections.

Accessing ASPX Controls in a Page Class
Add the code in the "Page" class of ShowOrdersTablePage.aspx.cs, located in:

...\<Application Folder>\Orders\ShowOrdersTablePage.aspx.cs

C#

public ShowOrdersTablePage()
{
    this.PreRender += new EventHandler(Page_PreRender);
}
 
private void Page_PreRender(object sender, EventArgs e)
{
    this.myTextbox.Text = "PAGE CLASS";
}

Visual Basic .NET:

Private Sub ShowOrdersTablePage_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
    Me.myTextbox.Text = "PAGE CLASS"
End Sub

Accessing ASPX Controls in TableControl and RecordControl Classes
Add your code in the TableControl class or RecordControl class of ShowOrdersTablePage.aspx.cs, located in:

.NET Framework 1.1:

...\$lt;Application Folder>\Orders\ShowOrdersTablePage.aspx.cs

.NET Framework 2.0:

...\<Application Folder>\<App_Code>\Orders\ShowOrdersTablePage.Controls.cs

C# .NET Framework 1.1 TableControl class:

public OrdersTableControl()
{
    this.PreRender += new EventHandler(TableControl_PreRender);
}
 
private void TableControl_PreRender(object sender, EventArgs e)
{
    this.Page.myTextbox.Text = "TABLE CLASS";
}

C# .NET Framework 1.1 RecordControl class:

public OrdersRecordControl()
{
    this.PreRender += new EventHandler(RecordControl_PreRender);
}
 
private void RecordControl_PreRender(object sender, EventArgs e)
{
    this.Page.myTextbox.Text = "RECORD CLASS";
}

C# .NET Framework 2.0 TableControl class:

public OrdersTableControl()
{
    this.PreRender += new EventHandler(TableControl_PreRender);
}
private void TableControl_PreRender(object sender, EventArgs e)
{
    System.Web.UI.WebControls.TextBox myTextbox =
        (System.Web.UI.WebControls.TextBox)(this.Page.FindControlRecursively("myTextbox"));
    myTextbox.Text = "TABLE CONTROL CLASS";
}

C# .NET Framework 2.0 RecordControl class:

public OrdersRecordControl()
{
    this.PreRender += new EventHandler(RecordControl_PreRender);
}
private void RecordControl_PreRender(object sender, EventArgs e)
{
    System.Web.UI.WebControls.TextBox myTextbox =
        (System.Web.UI.WebControls.TextBox)(this.Page.FindControlRecursively("myTextbox"));
    myTextbox.Text = "RECORD CONTROL CLASS";
}

Visual Basic .NET .NET Framework 1.1 TableControl class and RecordControl classes:

Private Sub myOrdersTableControlRecordControl_PreRender(ByVal sender as Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
 
    Me.Page.myTextbox.Text = "TABLE CONTROL AND RECORD CONTROL CLASS"
 
End Sub

Visual Basic .NET .NET Framework 2.0 TableControl and RecordControl classes

Private Sub myOrdersTableControlRecordControl_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
    Handles Me.PreRender
 
    Dim tempTextBox As System.Web.UI.WebControls.TextBox =
        CType(Me.Page.FindControlRecursively("myTextBox"),
    System.Web.UI.WebControls.TextBox)
    tempTextBox.Text = "TABLE CONTROL AND RECORD CONTROL CLASS"
End Sub

Note that "myTextBox" is the ID of the ASPX Textbox.

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