ASP.NET Custom Server Controls: Cute ASP.NET TextBox Control - Testing the control with a Web Application
(Page 3 of 6 )
The previous section just created the custom control. We need to test the custom control using a web application. Now, we shall create a web application (within the same solution as above), refer to the previous web control, drag it onto the web page and finally test it. The following steps would guide you through the process.
Within the same solution, Go to File -> Add Project -> New Project
Select the project type as “ASP.NET Web Application,” replace the location with “http://localhost/webapplication1” and click “ok.” Within the solution explorer, right-click on the solution, go to the properties, select the “Single Startup Project” radio button and select “SimpleCustomControlTest” in the dropdown list, which is right below that radio button and finally click “ok.”
Within the solution explorer open the “SimpleCustomControlTest” project and select “References.” Right-click on “references” and select “Add Reference.”
Within the “Add Reference” dialog box, select “Projects” tab and click on “select” button and click “ok” as shown in the following figure (2).

Open the tool box, right-click on “Web Forms” and select “Add/Remove Items.”
In the “Custom Toolbox” dialog box, click “browse” and go to the bin folder of the “SimpleCustomControl” project. Select the “SimpleCustomControl.dll” file, click “Open” and click “Ok.”
You should be able to see a new control within the “web forms” section of the tool box named “MyTextBox” (it generally gets added at the bottom).
Drag as many “MyTextBox”es as you want onto the “WebForm1.aspx” in design mode.
Drag two buttons and change the text as “Show” and “PostBack” respectively.
Modify the “button1_click” event (of “Show” button) as follows:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.MyTextBox1.Text = "hello world"
End Sub
Next: Understanding the MyTextBox >>
More ASP.NET Articles
More By Jagadish Chaterjee