.Net - Explain with code sample how to create a user
control. - June 03, 2009 at 11:00 AM by Shuchi Gauri
Explain with code sample how to create a user control.
Steps to create a User control:
a. Select a project
b. Right click and add a new item (User Control - .ascx) to the selected
project.
c. Add @Control Directive
d. Add all the controls that you want to be displayed on the User control as a
part of one or more web pages.
e. Write the code for all the tasks to be performed by the user control.
f. Create accessor methods for the outside world accessing this user control.
Using the User control:
Register the control on the webpage it needs to be used by putting @Register
directive.
Specify the following attributes to the register directive:
a. TagPrefix: defines the namespace in which the control would reside
b. TagName: defines the name with which control is referred
c. Src: Path of where the control is kept.
Control is then used on the page using the following code:
<TagPrefix:TagName />
Also read
Fragment cache is to store user controls individually within a web form in cache
instead of the whole webform as such. The idea is to simply have different
cache parameters for different user controls...........
Fragment caching refers to the caching of individual user controls within a Web
Form, Each user control can have independent cache durations and
implementations of how the caching behavior is to be applied................
User authored controls are which not part of the .net framework library. It
includes both custom controls and user controls.........
Steps to create inherited Control:-.........
|