Find Control in user control

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I have a user control which is dynamically loaded into a placeholder. I have
a formview in the user control

In the page load event of the user control I wand to find a dropdown in the
formview. I always get a null reference. It's really late and I guess it is
something obvious but I can't think. Regards, Chris.

Dim drp As New DropDownList

drp = CType(fvwAcknowlegement.FindControl("drpUploadType"), DropDownList)

drp.Visible = true
 
Chris said:
I have a user control which is dynamically loaded into a placeholder. I have
a formview in the user control

In the page load event of the user control I wand to find a dropdown in the
formview. I always get a null reference. It's really late and I guess it is
something obvious but I can't think. Regards, Chris.

Dim drp As New DropDownList

drp = CType(fvwAcknowlegement.FindControl("drpUploadType"), DropDownList)

drp.Visible = true

You can't find any form fields in the FormView, as it doesn't directly
contain any form fields. It contains a collection of items, and each
item has it's own set of form fields. You first have to access the
specific item you want, then you can access it's fields.
 
This code works when I put it in the item_created event of the formview.
Moreover this code works, in the page load of the control, when I manually
add the control to the page. It only causes a problem when the control is
added dyanically and I add the code to the page load event of the user
control. I don't understand why the controls seem to be added in a different
order when the user control is added dynamically. It's sort of working but I
would like to know why. Regards, Chris.
 
Back
Top