首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

动态加载用户控件,怎么设置控件属性

2012-01-13 
动态加载用户控件,如何设置控件属性?uc7:NewsListCategoryID 2 TitleLength 25 id NewsList1 ru

动态加载用户控件,如何设置控件属性?
<uc7:NewsList   CategoryID= "2 "   TitleLength= "25 "   id= "NewsList1 "   runat= "server "/>
然后这样:
UserControl   uc   =   (UserControl)LoadControl( "Modules/NewsList.ascx ");
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(uc);
加载是加载了,但是属性值怎么弄?

[解决办法]
UserControl uc = (UserControl)LoadControl( "Modules/NewsList.ascx ");


uc.TitleLength= 25;


PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(uc);
[解决办法]
楼上好快
[解决办法]
说了NewsList是你NewsList.ascx的类名,我这里是猜测的,具体是什么要看你的。

因为你必须强制转化成NewsList类才行。

我估计可能你要这样才行

Modules.NewsList uc = (Modules.NewsList)LoadControl( "Modules/NewsList.ascx ");

具体看你的NewsList.ascx的类名和命名空间
[解决办法]
MyUserControl uc = LoadControl( "Modules/NewsList.ascx ") as MyUserControl;
uc.MyProperty = ....

热点排行