FindControl in FormView Edit Template

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.
 
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.

Never mind. I got it.

Use the OnLoad event of the control.

Thanks,
Steve T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top