Use ASP. NET to register custom controls to Web. config

Source: Internet
Author: User

I downloaded a source code from the internet yesterday and found that I don't understand one of them, that is, the custom control can be used directly without the register command and compiled normally. I also think this is good. Otherwise, a custom control is often used, and every page used must be referenced, which is very troublesome, but now the problem is that I don't know how he does it. Then I searched the control name segment in the project and found that there was a section in Web. config.CodeAfter referencing this, I searched the internet and found that the custom control can be registered in Web. config, and then it can be used directly, instead of using register every time.

 

This new function is introduced in ASP. NET 2.0, namely:

You only need to declare it once in the new pages-> controls section of the web. config file of your application:

<? XML version = "1.0"?>

<Configuration>

<System. Web>

<Pages>
<Controls>

<Add tagprefix = "scottgu" src = "~ /Controls/header. ascx "tagname =" Header "/>
<Add tagprefix = "scottgu" src = "~ /Controls/footer. ascx "tagname =" footer "/>
<Add tagprefix = "controlvendor" assembly = "controlvendorassembly"/>
</Controls>
</Pages>

</System. Web>

</Configuration>

 

("~" In ASP. NET The symbol means "locating from the application root path". It provides a good way to avoid using "..." everywhere in your code.)

 

Then I started the experiment immediately, and the result failed for the first time. I put the ascx control file and the ASPX page file in the same default directory, but when I build it, the system prompts that it seems impossible, then I move ascx to a new folder, and then in the web. the configuration is changed accordingly in config!

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.