D
Dennis
Gozirra said:Here's what I did to find the a single label called Label1 on my page.
This code is in my page_load and obviously does nothing more than find
the control and write its ID to the page.
Dim lblTest As Label
lblTest = CType(Me.FindControl("Label1"), Label)
Response.Write(String.Format("Label ID using Me.FindControl is
{0}.", lblTest.ID))
Response.Write("<BR>")
lblTest = CType(Form1.FindControl("Label1"), Label)
Response.Write(String.Format("And the ID using Form1 is {0}.",
lblTest.ID))
Form1 is automatically included on any aspx page and is set as
runat="server". By default there is no declaration for this object and
there usually isn't a need for it. In the case of the sample code
above, I have declared Form1 as:
Protected Form1 As System.Web.UI.HtmlControls.HtmlForm
So in the first instance I used Me.FindControl to get a reference to
label1 and write its id. I then use the Form1 object to find the
control again and once again outputs its ID.
I hope this helps.
Thanks. I get an error "Name 'Form1' is not declared.", but if take
that out it works.
I figured out that the reason me.findcontrol doesn't work on my page is
because I'm using a master page.