Accessing controls defined inside DataRepeater within Page_Load

Posted by xander on Stack Overflow See other posts from Stack Overflow or by xander
Published on 2009-10-19T01:02:11Z Indexed on 2010/05/11 22:04 UTC
Read the original article Hit count: 290

Filed under:
|

I have a series of controls, 3 of which I need to disable.

protected void AddToCart_Click(object sender, CommandEventArgs e) {

        //some other code...

        LinkButton ctrl = (LinkButton)sender;
        RepeaterItem rpItem = ctrl.NamingContainer as RepeaterItem;
        if (rpItem != null) {
            LinkButton btn = (LinkButton)rpItem.FindControl("btnRemoveFromCart");
            btn.Visible = true;
            btn = (LinkButton)rpItem.FindControl("btnAddToCart");
            btn.Visible = false;
            Image img = (Image)rpItem.FindControl("imgAdded");
            img.Visible = true;
        }

I want to access the DataRepeater and get to the controls to disable them. Only on Page_Load.

protected void Page_Load(object sender, EventArgs e) {
        string galleryID = Session["selectedGalleryID"].ToString();
        getItems();

        if (!IsPostBack) {
            h1GalleryTitle.InnerText = Session["selectedGalleryName"].ToString();
                //the code will go here to initially disable the controls that need to be disabled...
        }
    }

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#