ComponentOne TabControl for ASP.NET AJAX: TabControl for ASP.NET AJAX Task-Based Help > Adding a C1TabControl in Code

Adding a C1TabControl in Code

In some instances, you may want to add a C1TabControl control to your project in code. In this topic, you will learn how to create a C1TabControl control with three C1TabPage objects using C# and Visual Basic code.

Complete the following steps:

1.   Add a PlaceHolder control to your page.

2.   In Design view, double-click the page to add a Page_Load event to the project and to switch to the code editor.

3.   Import the following namespace into your project:

      Visual Basic

Imports C1.Web.UI.Controls.C1TabControl

      C#

using C1.Web.UI.Controls.C1TabControl;

4.   Create the C1TabControl object, set its Width and Height, and then add it to your project by placing the following code in the Page_Load event:

      Visual Basic

Dim NewTabControl As C1TabControl = New C1TabControl()

NewTabControl.Width = 300

NewTabControl.Height = 200

PlaceHolder1.Controls.Add(NewTabControl)

      C#

C1TabControl NewTabControl = new C1TabControl();

NewTabControl.Width = 300;

NewTabControl.Height = 200;

PlaceHolder1.Controls.Add(NewTabControl);

5.   Create three C1TabPage objects and add them to the C1TabControl. This code should also be added to the Page_Load event.

      Visual Basic

'Create three C1TabPage objects

Dim C1TabPage1 As C1TabPage = New C1TabPage()

Dim C1TabPage2 As C1TabPage = New C1TabPage()

Dim C1TabPage3 As C1TabPage = New C1TabPage()

 

'Set the TabPages' 'Text' Property

C1TabPage1.Text = "C1TabPage1"

C1TabPage2.Text = "C1TabPage2"

C1TabPage3.Text = "C1TabPage3"

 

'Add the three C1TabPage objects to the C1TabControl

NewTabControl.TabPages.Add(C1TabPage1)

NewTabControl.TabPages.Add(C1TabPage2)

NewTabControl.TabPages.Add(C1TabPage3)

      C#

//Create three C1TabPage objects

C1TabPage C1TabPage1 = new C1TabPage();

C1TabPage C1TabPage2 = new C1TabPage();

C1TabPage C1TabPage3 = new C1TabPage();

 

//Set the TabPages' 'Text' Property'

C1TabPage1.Text = "C1TabPage1";

C1TabPage2.Text = "C1TabPage2";

C1TabPage3.Text = "C1TabPage3";

 

//Add the three C1Tab objects to the C1TabControl

NewTabControl.TabPages.Add(C1TabPage1);

NewTabControl.TabPages.Add(C1TabPage2);

NewTabControl.TabPages.Add(C1TabPage3);

6.   Run the program.

 This Topic Illustrates the Following:

When your project is run, your C1TabControl control will resemble the following image:

 


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.