• accessing child controls in

    Posted on December 11th, 2008 admin No comments

    This past week, I had a hard time figuring out what I would like to happen in my website.
    The scenario is like this:
    I want a little image in my website to display a profile’s photo when they user is logged in. So I used asp:LoginView control to accomplish it. Inside this control, I have 2 templates, the anonymoustemplate and loggedintemplate, inside the loggedintemplate, I put an asp:Imaage control and left blank the ImageUrl property so I can programmatically assign it to the profile property called PathToPhoto. The problem is that, in the page_load event of that page, when I tried to assign the ImageUrl property into the persons profile, it says that the image object is not declared. I read MSDN, and what I found out is that, the image control is a child of the loginview control, It took me 3 days of trying to figure out what syntax to use so I can access the members of the child control. Unfortunately I didnt get what I was looking for, So I push my way thru asp.net and tricked it. I used FindControl method of the loginviewcontrol to find out if a certain control is loaded by using its id.

    Dim MyCollection As ControlCollection
    MyCollection = LoginView1.Controls
    Dim MyControl As Control
    MyControl = MyCollection.FindControl(”ImageID”)
    If(Not MyControl Is Nothing)
    Dim MyImage As Image = New Image
    MyImage.ImageUrl = Profile.PathToPhoto
    MyCollection.Add(MyImage)
    End If

    I know this is not the most effecient way to do it, But at least it serves the purpose, Im gonna have to further search the web for the proper way of doing it.

    Leave a reply