中创建UserControl我的最终目标是在我的App_Code文件夹中的类中创建一个UserControl,并将其中的html呈现为字符串。asp.net无法在类
HTML的人丁可以用这个例子来完成我相信: How do I get the HTML output of a UserControl in .NET (C#)?
我的问题:
我创建
public partial class Controls_MyUserControl : System.Web.UI.UserControl
我已经注册在我的用户控件我的web.config
<add tagPrefix="UC" src="~/Controls/MyUserControl.ascx" tagName="MyUserControl" />
我可以当我尝试创建一个类此控制类型的对象(在我的App_Code文件夹)页面就好
<UC:MyUserControl ID="MyUserControl1" runat="server" />
上还有引用此它不允许我。
Controls_MyUserControl dummy = new Controls_MyUserControl();
潜在奇怪的是,当我把这个代码放到页面的后面的代码,它的工作原理。
我需要做什么才能在我的课程app_code文件夹中创建usercontrol的任何想法?
我的猜测是,我需要在顶部的“using”语句中引用控件,但我不确定那会是什么。
它不在我所知的命名空间中(至少在实际用户控件的后面的代码中没有命名空间)。虽然我不确定它是否从System.Web.UI.UserControl继承。张贴由斯科特·阿伦
在此先感谢