(VS2005)动态加载用户控件,属性赋值问题

photoshoplxy 2006-02-16 10:15:23
VS2003中可以,VS2005中就不行,郁闷啊!请高手指点

用户控件完整代码如下:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Controls_FriendsHeader : System.Web.UI.UserControl
{
public string message;
public string imageurl;

public string Message
{
get { return this.message; }
set { this.message = value; }
}

public string IconImageUrl
{
get { return this.imageurl; }
set { this.imageurl = value; }
}

protected override void OnPreRender(EventArgs e)
{
if (this.Message != String.Empty)
{
this.lblWelcome.Text = message;
}
if (this.IconImageUrl != String.Empty)
{
this.imgIcon.ImageUrl = imageurl;
}
base.OnPreRender(e);
}
protected void Page_Load(object sender, EventArgs e)
{

}
}



加载用户控件的类代码 如下:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// FriendsBase 的摘要说明
/// </summary>
public class FriendsBase : System.Web.UI.Page
{
protected string HeaderMessage;
protected string HeaderIconImageUrl;
public FriendsBase()
{

//
// TODO: 在此处添加构造函数逻辑
//
}
protected override void Render(HtmlTextWriter writer)
{
Controls_FriendsHeader head;

Control form = Page.Controls[1];

Controls_FriendsHeader head = (Controls_FriendsHeader)LoadControl("Controls/FriendsHeader.ascx");

head.Message = HeaderMessage;
head.IconImageUrl = HeaderIconImageUrl;
form.Controls.AddAt(0, head);

form.Controls.AddAt(1, new nSubHeader.SubHeader());

Control footer = LoadControl("Controls/FriendsFooter.ascx");
form.Controls.AddAt(Page.Controls[1].Controls.Count, footer);
base.Render(writer);
}
}

问题:想在类中加入用户控件的属性,编译器告诉我没有using,Controls_FriendsHeader无效.
请问怎么解决,万分感谢!

注:
我在一个aspx页面中,用Register这个用户控件,可以在后台代码页(aspx.cs)引用Controls_FriendsHeader,没有用Register的是不能.
...全文
127 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2006-02-24
  • 打赏
  • 举报
回复
right-click on the References folder in the solution explorer and click Add Reference. The displayed list shows .NET components that are recognized by the IDE. Our component is not in this list yet, so click on the Browse button. Again, find the .NET component called BuildingCustomControls.dll that we discussed earlier. Click Open, click OK.
meixiaofeng 2006-02-24
  • 打赏
  • 举报
回复
没有引用

17,748

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧