在 App_Code 类中强制转换 ascx
我有一个 ascx,我想从 App_Code 中的类加载和转换它。尽管我可以从 aspx 页面让它工作,但我无法从 App_Code 类让它工作。
ASPX 页面技术可以与以下代码配合使用:(
pc = LoadControl("enquirycapture.ascx");
((ASP.enquirycapture_ascx)pc).CustomProperty = customObject;
注意:我在 aspx 页面中有以下内容:)
<%@ Reference VirtualPath="~/enquirycapture.ascx" %>
但是,当我尝试从 App_Code 类中转换控件时,它无法“看到”ascx 类,并且因此我无法投射到它来设置自定义属性(我可以加载它,但不能投射它)。我不知道如何复制 <% Reference...>来自 App_Code 类中的东西。有人知道我如何从 App_Code 类中引用(从而转换)我的 ascx 吗?谢谢。
I have an ascx which I want to load and cast from a class sitting within App_Code. I can't get it to work from the App_Code class, although I can get it to work from an aspx page.
The ASPX page technique works fine with the following code:
pc = LoadControl("enquirycapture.ascx");
((ASP.enquirycapture_ascx)pc).CustomProperty = customObject;
(Note: I have the following in the aspx page:)
<%@ Reference VirtualPath="~/enquirycapture.ascx" %>
However, when I try casting the control from within the App_Code class then it can't 'see' the ascx class, and therefore I am unable to cast to it to set the custom properties(I can load it, but not cast it). I don't know how to replicate the <% Reference...> thing from within the App_Code class. Anyone know how I can reference (and thus cast) my ascx from the App_Code class? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
App_Code
编译为单独的程序集,无法引用 CodeFile 中的类型。但是您可以将接口/基类添加到您的
App_Code
文件夹中,该文件夹标识您打算在用户控件中实现的自定义属性和方法:然后
最后在
App_Code
中的某个位置:App_Code
compiles to a seperate assembly that can't reference types in a CodeFile.But you can add interface/base class to your
App_Code
folder that identifies the custom properties and methods that you intend to implement in your usercontrol:and then
and finally somewhere in
App_Code
: