[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

Re: Access Controls nested in a FormView

RGF

8/22/2007 3:37:00 PM

On Aug 21, 12:41 pm, rowe_newsgroups <rowe_em...@yahoo.com> wrote:
> On Aug 21, 1:21 pm, RGF <Raf.Figue...@gmail.com> wrote:
>
>
>
> > 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 thecontrolproperties
> > when embedded inside of aFormViewcontrol.
>
> > What I am trying to do is to enable or disable a textboxcontrol
> > programatically by accessing the property of thecontrol, along the
> > lines of:
>
> > textbox1.Enable = false
>
> > However, when the textboxcontrolis embedded in aFormviewnested 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 aformviewwhile using
> > VB.Net & .Net Frame Work 2.0?
>
> > -r
>
> 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



2 Answers

Ladislav Mrnka

8/22/2007 7:00:00 PM

0

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

"RGF" wrote:

> On Aug 21, 12:41 pm, rowe_newsgroups <rowe_em...@yahoo.com> wrote:
> > On Aug 21, 1:21 pm, RGF <Raf.Figue...@gmail.com> wrote:
> >
> >
> >
> > > 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 thecontrolproperties
> > > when embedded inside of aFormViewcontrol.
> >
> > > What I am trying to do is to enable or disable a textboxcontrol
> > > programatically by accessing the property of thecontrol, along the
> > > lines of:
> >
> > > textbox1.Enable = false
> >
> > > However, when the textboxcontrolis embedded in aFormviewnested 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 aformviewwhile using
> > > VB.Net & .Net Frame Work 2.0?
> >
> > > -r
> >
> > 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
>
>
>
>

RGF

8/23/2007 12:11:00 AM

0

On Aug 22, 2:00 pm, Ladislav Mrnka
<LadislavMr...@discussions.microsoft.com> wrote:
> 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
>
> "RGF" wrote:
> > On Aug 21, 12:41 pm, rowe_newsgroups <rowe_em...@yahoo.com> wrote:
> > > On Aug 21, 1:21 pm, RGF <Raf.Figue...@gmail.com> wrote:
>
> > > > Hi, I am using servercontrols(textbox, dropdownlist, calendar)
> > > > inside of a form view, it seems that the .Net framework (VB.Net & Net
> > > > Frame Work 2.0) makes it difficult toaccessthecontrolproperties
> > > > when embedded inside of aFormViewcontrol.
>
> > > > What I am trying to do is to enable or disable a textboxcontrol
> > > > programatically by accessing the property of thecontrol, along the
> > > > lines of:
>
> > > > textbox1.Enable = false
>
> > > > However, when the textboxcontrolis embedded in aFormviewnested 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 ofcontrolsembedded inside of aformviewwhile using
> > > > VB.Net & .Net Frame Work 2.0?
>
> > > > -r
>
> > > 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 toaccessthe 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

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