ASP. NET user controls can also be referenced in Web. config

Source: Internet
Author: User

When we reference a user control, if there are many files that reference the control, it is really painful to add the register command to every page.

Fortunately, we can register the control in Web. config:

<Configuration>
<System. Web>
<Pages>
<Controls>
<Add tagprefix = "mycontrol" src = "~ /Controls/webusercontrol. ascx "tagname =" mybutton "/>
</Controls>
</Pages>
</System. Web>
</Configuration>
Third-party controls can also be registered here.

 

<Configuration>
<System. Web>
<Pages>
<Controls>
<Add tagprefix = "controlvendor" assembly = "controlvendorassembly"/>
</Controls>
</Pages>
</System. Web>
</Configuration>
Note that "~" in the above User Control Syntax. For those who are not familiar with this symbol, "~" in ASP. NET The symbol means "locating from the application root path". It provides a good way to avoid using "..." everywhere in your code. In the web. when declaring a user control in the config file, you should always use it, because the page may use controls in different subdirectories, therefore, you should always locate these controls from the root path of the application.

Once you are on the web. after these controls are declared in the config file, you can use them on any page, dashboard page, or user control on your website, as shown in the following figure (you no longer need to register commands ):







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.