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 ):