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.
<%@ 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.
No comments:
Post a Comment