An embarrassing thing is that before the Spring Festival holiday, I wrote a piece of code. I don’t know why, ASPX can load the code in ASCX.cs, but cannot load the source file in ASCX. Because I can’t calm down, I can’t. After solving this problem, I came back to work today and found that the problem was caused by incorrectly writing the @Register command of ASPX.
The correct way should be written as follows:
<%@ Register TagPrefix="myTagPrefix" TagName="ConfigNavigation" Src="/Controls/ConfigNavigation.ascx" %> But I wrote it as follows:
<%@ Register TagPrefix="myTagPrefix" Namespace="MyWEB.Controls" Assembly="MyWebProject" %>The latter way of writing will only load the class corresponding to the cs file, but not the content in ascx, thus appearing The problem I encountered here.
The following is a summary of several ways to write the @Register command, compiled with reference to MSDN's http://msdn.microsoft.com/zh-cn/library/c76dd5k1.aspx :
<%@ Register tagprefix="tagprefix" namespace="namespace" assembly="assembly" %>
<%@ Register tagprefix="tagprefix" namespace="namespace" %>
<%@ Register tagprefix="tagprefix" tagname="tagname" src="pathname" %>Each attribute is described as follows:
tagprefix
An arbitrary alias that provides a short reference to the namespace of the tag used in the file containing the directive.
namespace The namespace of the custom control being registered.
tagname Any alias associated with the class. This property is only used for user controls.
assembly The assembly that resides in the namespace associated with the tagprefix attribute.
The assembly name cannot include the file extension. Also note that if the assembly attribute is missing, the ASP.NET analyzer assumes that the source code exists in the application's App_Code folder. If you want to register the control's source code on the page without compiling it, place the source code in the App_Code folder. ASP.NET dynamically compiles the source files in the App_Code folder at run time.
The location (relative or absolute) of the declarative ASP.NET user control file associated with src and the tagprefix:tagname pair.
The src attribute value can be either a relative path or an absolute path from the application's root directory to the user control source file. For ease of use, it is recommended to use relative paths. For example, assume that all of your application's user control files are stored in the Usercontrol subdirectory of the application root directory. To include the user control in the Usercontrol1.ascx file, include the following in the @Register directive:
Src="~usercontrolusercontrol1.ascx" The tilde (~) character represents the root directory of the application