Understanding User Controls in .NET Framework

Though you can apply multiple server controls in your web form, ASP.NET allows you to create new controls according to your requirements. The controls that you create are called ASP.NET User Controls. ASP.NET User Controls have .ascx extension. The biggest advantage of ASP.NET User Controls is that it allows you to save a part of the web form and reuse it many other web forms. This drastically reduces the developers’ time.

ASP.NET User Controls are self-contained entities that are saved in an independent file. You can relate a user control with a “black box”. ASP.NET User Controls are very helpful when you want to use functionality on multiple pages of a web-application. For example, if you want to use a site navigation header or footer on all the pages of the web application, you can create this site navigation header or footer as a user control in a separate page. You do not need to place this user control on each and every page. You just have to write a few lines code to call the user control.

As ASP.NET User Controls are self-contained the developers working on the same project need not worry about transgressing on other’s code. ASP.NET User Controls offer a great deal of functionality than Server-side Includes (SSIs). Using SSIs in encapsulating the site functionality is a quite tedious task when compared to ASP.NET User Controls. You can create a user control by using the Register directive. This process is called registering the user control. For instance, you can use this code to register a user control:

<%@ Register TagPrefix="sampNamespace" TagName="Myname" Src="mypage.ascx" %>

The TagPrefix is the exclusive namespace provided to the user control so that multiple ASP.NET User Controls with similar name can be discriminated from each other. The TagName is the name of the user control and the Src is the virtual path to the user control. After registering the user control you can place the tag of the user control in an appropriate location on the web form. You have to include the runat=”server” attribute with the tag.

You can create a user control using only one programming language for a web form. However, you can create multiple ASP.NET User Controls for a web form. For example, you can create a user control using C# and another user control using VB.NET and use both the ASP.NET User Controls on the same web form.


| Converting Web Pages to User Controls in .NET | .Working on .NET User Controls | Overview of ASP.NET User Controls | Web User Controls - Creation and Implementation | Advantages of using User Controls in ASP.NET | Re-usability of User Controls in ASP.NET | Personalizing Web Application by Creating User Controls in .NET | Customizing your Application with VB.net User Controls | Building User Controls in ASP.NET | Examples of User Controls in VB.NET | Example of C# User Controls | Where to use Visual Basic User Controls | Working on User Interface Controls | Creating Dynamic User Controls | Understanding VB .NET User Controls | Creating User Controls VB.NET | How to load user controls dynamically |



“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.