Subscribe

RSS Feed (xml)

Adding a User Control to a Web Form in ASP.NET

You must first register the User Control on the page before you can insert it like a regular
control. At the top of the ASPX page, add the following:
<%@ Register TagPrefix=”AspNetCookbook” TagName=”SampleControl”
Src=”SampleControl.ascx” %>
In the ASPX page where you want to insert the control:
<AspNetCookbook:SampleControl runat=”server” />
The @ Register directive allows you to specify the prefix of the tag (TagPrefix), the
name of the tag (TagName), and the relative location of the User Control (Src) to associate
with the specified tag prefix and tag name.The User Control is then inserted; for
example, <TagPrefix:TagName runat=”server” />.
Users of Visual Studio .NET will note that there is very limited designer support for
user controls, and that in HTML view there is no code completion for prefixes specified
in <%@ Register %> blocks on a page.

No comments:

Archives

Variety in the Web World