Creating User Controls without Interface
Author: Faraz
Download Source Code : 721_SampleCode.zip
In this sample article I will try to explain you how you can create user controls in ASP.Net without any user control interface.
This sample article will elaborate you how you can create the user controls only containing the server functions. This sometimes help you in creating web controls which has limited functionalities means you don’t want to add the any server controls or you want to access the properties by using getter setter.
To begin with create a solution in VS 2005 and add the user control in your solution. Note you must uncheck the option of adding the .vb file (code behind file)
The final code of your user control will be look like as follows:
Here you will see I have defined one function and one property with only getter that gets the PI value and the function that returns the PI value by rounding it to up to three decimal places.
On your .aspx page you need to register the user control using register tag:
On form add the user control and two label control which is used to display the value on web form so the control on your aspx form will be look like as follows:
The only thing left is call your user control methods using the user control id and this will displays the PI value on your web form like: