By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,684 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,684 IT Pros & Developers. It's quick & easy.

FindControl in FormView Edit Template

P: n/a
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.

Jun 5 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jun 5, 11:48 am, SteveT <sg.ta...@srs.govwrote:
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.

Jun 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.