Creating User Controls
Creating User Controls
Page3.aspx
Page1.aspx
Page2.aspx
Why Use User Controls?
User controls offers many advantages when developing a Web
application:
User controls are self contained
User controls provides separate variable namespaces, which
means that none of the methods and properties of user control
conflict with any existing methods or properties of the hosting
page.
User controls can be used more than once within the hosting
page, without causing property and method conflicts.
User controls can be written in a different language from the
main hosting page. Eg: A user control is written in C# and Web
form is written in VB.NET.
Why Use User Controls?
The examples where a user control simplifies Web page development:
• Text box to only accept integers in a specific range. The user control
would include validation controls.
• Data grid control that always connects to the same data source, to display
data from a stored procedure or table.
•Grouping of text boxes and other controls to accept mailing information
( name, address, state, city, postcode) form user.
•Grouping of text boxes and other controls to accept contact information
(home telephone number, business telephone number, mobile telephone,
e-mail address) form user.
Adding a User Control
Use the @ Register directive to include a user control in an
ASP.NET Page
<uc1:WebUserControl ID="WebUserControl1"
runat="server" />
Adding a User Control
Use Get and Set properties of the user control to expose the
values of text box to the host.
or