如何为Web用户控件的属性赋值。 [英] How to assign value to the property of web user control.
本文介绍了如何为Web用户控件的属性赋值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个Web用户控件并创建了它的属性。
I have created one web user control and created its property as well.
public string Volume
{
get
{
return Session["VOLUME"].ToString();
}
set
{
Session["VOLUME"] = value;
}
}
现在,我已将此网络用户控件放在转发器中。
当我是试图在Repeater中搜索Web用户控件的这个卷属性,我没有得到这个,我到目前为止尝试的代码:
now, i have placed this web user control in a Repeater.
when i'm trying to search for this "Volume" property of Web User Control in Repeater, i'm not getting this, code i tried so far:
if (Repeater1.Items[index].ItemType == ListItemType.Item || Repeater1.Items[index].ItemType == ListItemType.AlternatingItem)
{
Repeater r1 = Repeater1.Items[index].FindControl("Repeater1") as Repeater;
if (r1 != null)
{
foreach (RepeaterItem item in r1.Items)
{
UserControl u = (UserControl)item.FindControl("SubChemicals1");
if (u != null)
{
u.;// Not able to get the property of userscontrol which i defined
}
}
}
}
有谁能帮助我获取此UserControl的属性?
Can anyone please help me to get the property of this UserControl?
推荐答案
你需要添加一些如下所示的属性
you need to add few attributes like below
[EditorBrowsable(EditorBrowsableState.Always)]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string Volume
{
get
{
return Session["VOLUME"].ToString();
}
set
{
Session["VOLUME"] = value;
}
}
当你施放时,你需要施放它对你的用户控制如下(假设你的用户控件类名是SubChemicals
when you cast, you need to cast it to your user control like below ( assume your user control class name is SubChemicals
SubChemicals u = (SubChemicals)item.FindControl("SubChemicals1");
这篇关于如何为Web用户控件的属性赋值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文