Question : Findcontrol (How do I?)

I have a master page, in a content area I have a repeater, and in the repeater  I have a label.

How do I get a handle on the label to get/set its value?

I need to do this outside of any item commands so e.item.findcontrol will not work, I have to get to it from the page.master..... but cant seem to get it.

Andy

Code Snippet:
1:
2:
3:
4:
5:

    
        

Answer : Findcontrol (How do I?)

Hi CarmelinaD,

I've added to button click event handlers one for a button on the master page and one for a button on the client page.  Note the me.Master.FindControl if the button is on the content page.

Could you also break point any other code that you might have which updates or databinds the control you're trying to change with your button click even as it's possible these are overwriting your changes after your button click event.

Good luck.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
'If you button is on the master page
Protected Sub btnMaster_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim r As Repeater = DirectCast(ContentPlaceHolder1.FindControl("Repeater1"), Repeater)
    
    For Each ri As RepeaterItem In r.Items
        Dim l As Label = DirectCast(ri.FindControl("Label1"), Label)
        l.Text = "This is Label1 after btnMaster click"
    Next
End Sub
 
'If your button is on the content page
Protected Sub btnContent_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim cph As ContentPlaceHolder = DirectCast(Me.Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
    
    Dim r As Repeater = DirectCast(cph.FindControl("Repeater1"), Repeater)
    
    For Each ri As RepeaterItem In r.Items
        Dim l As Label = DirectCast(ri.FindControl("Label1"), Label)
        l.Text = "This is Label1 after btnContent click"
    Next
End Sub
Random Solutions  
 
programming4us programming4us