Access Controls nested in a FormView

R

RGF

Hi, I am using server controls (textbox, dropdownlist, calendar)
inside of a form view, it seems that the .Net framework (VB.Net & Net
Frame Work 2.0) makes it difficult to access the control properties
when embedded inside of a FormView control.

What I am trying to do is to enable or disable a textbox control
programatically by accessing the property of the control, along the
lines of:

textbox1.Enable = false

However, when the textbox control is embedded in a Formview nested in
the EditItemTemplate then the textbox is Not accessible. I would
think that the following syntax should work, but it does not:


FormView1.EditItemTemplate.Textbox1.Enable = false


Could anyone suggest the proper syntax for me to Get/Set the
properties of controls embedded inside of a formview while using
VB.Net & .Net Frame Work 2.0?

-r
 
R

rowe_newsgroups

Hi, I am using server controls (textbox, dropdownlist, calendar)
inside of a form view, it seems that the .Net framework (VB.Net & Net
Frame Work 2.0) makes it difficult to access the control properties
when embedded inside of a FormView control.

What I am trying to do is to enable or disable a textbox control
programatically by accessing the property of the control, along the
lines of:

textbox1.Enable = false

However, when the textbox control is embedded in a Formview nested in
the EditItemTemplate then the textbox is Not accessible. I would
think that the following syntax should work, but it does not:

FormView1.EditItemTemplate.Textbox1.Enable = false

Could anyone suggest the proper syntax for me to Get/Set the
properties of controls embedded inside of a formview while using
VB.Net & .Net Frame Work 2.0?

-r

IIRC You must use find the control using the FindControl method and
cast the returned control into the appropriate type.

Off the top of my head it should be something like:

Dim tb as TextBox = DirectCast(FormView1.FindControl("TextBox1"),
TextBox)
tb.Enabled = False

Thanks,

Seth Rowe
 
R

RGF

IIRC You must use find thecontrolusing the FindControl method and
cast the returnedcontrolinto the appropriate type.

Off the top of my head it should be something like:

Dim tb as TextBox = DirectCast(FormView1.FindControl("TextBox1"),
TextBox)
tb.Enabled = False

Thanks,

Seth Rowe

Seth, thanks for the quick response.

Your suggestion resolved partly the problem I raised, that is, I am
able to access the control and get the existing value (text,
etc.)..:) but...

While I am able to "Get" (read) the correct text value (see sample
code below) by calling < MsgBox(tb.Text) > , however the following Set
argument < tb.Enabled = False > does not seem to take effect on the
control. After the method is executed, setting the Enabled property
to False, the textbox control remains enabled - Any thoughts on this
side effect? I would think I should be able to "Set" the properties
of the control, right?

Thanks in advanced,
-r


Partial Class Users_Details4
Inherits System.Web.UI.Page

Protected Sub FormView1_ItemUpdated(ByVal sender As Object, ByVal
e
As System.Web.UI.WebControls.FormViewUpdatedEventArgs) Handles
FormView1.ItemUpdated

Dim tb As TextBox =
DirectCast(FormView1.FindControl("TitleTextTextBox"), TextBox)

Dim Cal As Calendar =
DirectCast(FormView1.FindControl("Calendar1"), Calendar)

'Note: e Cal.SelectedDate = 9/22/2007 and Date.Today = 8/22/2007

If Cal.SelectedDate >= Date.Today Then

MsgBox(tb.Text) 'Display the text found in the control
tb.Enabled = False 'Set the State of the control

End If

End Sub

End Class
 
G

Guest

Hi,
are you calling DataBind on your FormView after you disable text box? Or
moreover is databinding performed after you disable text box (it can be
performed when some key properties or tepmlates of form view are changed)?
You can check this by implementing handler for DataBound on your FormView and
put break point to it. If so, try to disable your text box in DataBound
handler.

Regards,
Ladislav
 
R

RGF

Hi,
are you calling DataBind on yourFormViewafter you disable text box? Or
moreover is databinding performed after you disable text box (it can be
performed when some key properties or tepmlates of form view are changed)?
You can check this by implementing handler for DataBound on yourFormViewand
put break point to it. If so, try to disable your text box in DataBound
handler.

Regards,
Ladislav

Hi Ladislav,
I have a SQLDataSource adapter binding the Form, thus all of the child
controls in the FormView's ItemTemplate and EditItemTemplate are
databound controls. If I break the databind, the form will not
display the user data which is a business requirement, that is, by
Enable = False (disabling) the control the user will be able to see
their data but not alter it.

Just for my understanding would you share a bit more behind you logic,
cuz, I seem not to understand why would the databind would imped
Setting properties in the child control (i.e.: Textbox1.Enable =
False)

Thanks,
-r
 

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

Top