我正在我的 ASPX 页面上引用用户控件,我想知道这两个页面指令之间有什么区别。
最佳答案
@Register
主要用于注册标记前缀,以便以声明方式在页面内使用控件。
<%@ Register tagprefix="my" namespace="MyNamespace" %>
<my:CustomControl runat=server />
@Reference
主要用于引用页面或用户控件(通过文件名或虚拟路径),以以编程方式引用成员页面或控件的。
<%@ Reference Control="MyControl.ascx" %>
<% MyControl ctrl = (MyControl) Page.LoadControl("MyControl.ascx");
ctrl.CustomProperty = "..."; //REFERENCE directive is needed to access property
%>
关于ASP.NET @Register 与 @Reference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4840985/