FindControl in FormView Edit Template

  • Thread starter Thread starter SteveT
  • Start date Start date
S

SteveT

Before I pull out what little hair I have left, I'm swallowing my
pride and asking the Oracles of .Net:

I'm trying to set a property in a dropdown list control in a
FormView, based on a session parameter. The control is in the edit
template of the FormView, which is not visible from the view
template. I'm able to change properties of controls on the view
template. However, when trying to set them on the edit template the
control fails to instantiate. I have tried using the FormView
ModeChanged event but, the FormView does not render to the edit
template prior to the ModeChanged event firing. I stepped through the
code and the event fires before the FormView shows the edit template
and therefore the control is not visible to the code. Is there
another event to use for controls on the edit template?

Code:
Protected Sub fv1_ModeChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles fv1.ModeChanged
If fv1.CurrentMode = FormViewMode.Edit And Session("Type").ToString()
= "T" Then
Dim ddl As DropDownList = fv1.FindControl("ddl2")
ddl.Enabled = True
ddl.Dispose()
End If
End Sub

The code works if the control is on the view template, but fails if
the control is on the edit template. I set a test button on the edit
template to trigger the property change and it works.

Thanks,
Steve T.
 
Before I pull out what little hair I have left, I'm swallowing my
pride and asking the Oracles of .Net:

I'm trying to set a property in a dropdown list control in a
FormView, based on a session parameter. The control is in the edit
template of the FormView, which is not visible from the view
template. I'm able to change properties of controls on the view
template. However, when trying to set them on the edit template the
control fails to instantiate. I have tried using the FormView
ModeChanged event but, the FormView does not render to the edit
template prior to the ModeChanged event firing. I stepped through the
code and the event fires before the FormView shows the edit template
and therefore the control is not visible to the code. Is there
another event to use for controls on the edit template?

Code:
Protected Sub fv1_ModeChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles fv1.ModeChanged
If fv1.CurrentMode = FormViewMode.Edit And Session("Type").ToString()
= "T" Then
Dim ddl As DropDownList = fv1.FindControl("ddl2")
ddl.Enabled = True
ddl.Dispose()
End If
End Sub

The code works if the control is on the view template, but fails if
the control is on the edit template. I set a test button on the edit
template to trigger the property change and it works.

Thanks,
Steve T.

Never mind. I got it.

Use the OnLoad event of the control.

Thanks,
Steve T.
 
Back
Top