Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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;
    }
}

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
            }
        }
    }
}

Can anyone please help me to get the property of this UserControl?
Posted
Updated 27-Apr-14 6:24am
v2

1 solution

you need to add few attributes like below
C#
[EditorBrowsable(EditorBrowsableState.Always)]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public string Volume
        {
            get
            {
                return Session["VOLUME"].ToString();
            }
            set
            {
                Session["VOLUME"] = value;
            }
        }



when you cast, you need to cast it to your user control like below ( assume your user control class name is SubChemicals

C#
SubChemicals u = (SubChemicals)item.FindControl("SubChemicals1");
 
Share this answer
 
v3
Comments
abdul subhan mohammed 27-Apr-14 12:04pm    
i'm getting red underline for 'Browsable(true) n 'DesignerSerializationVisibility'
abdul subhan mohammed 27-Apr-14 12:06pm    
do i have to add Using System.ComponentModel ??
DamithSL 27-Apr-14 12:08pm    
yes
abdul subhan mohammed 13-May-14 2:51am    
can u check this link plz, to help me,
http://www.codeproject.com/Questions/772471/Problem-with-the-menu-in-asp-net
DamithSL 27-Apr-14 12:06pm    
do you have using System.ComponentModel; at the top of you class?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900