Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Accessing Controls nested in a formview (http://www.velocityreviews.com/forums/t780127-accessing-controls-nested-in-a-formview.html)

RGF 08-21-2007 05:19 PM

Accessing Controls nested in a formview
 
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


Riki 08-22-2007 03:18 PM

Re: Accessing Controls nested in a formview
 
"RGF" <Raf.Figueroa@gmail.com> wrote in message
news:1187716766.697840.217400@22g2000hsm.googlegro ups.com...
> 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?


Use FindControl:

CType(FormView1.FindControl("TextBox1"),TextBox).E nabled = false;

--

Riki



RGF 08-22-2007 03:24 PM

Re: Accessing Controls nested in a formview
 
On 21 ago, 12:19, 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 toaccessthe control properties
> when embedded inside of aFormViewcontrol.
>
> 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 aFormviewnestedin
> 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


Update:

I am able to "Get" (read) the value - see sample code below, the <
MsgBox(tb.Text) > does retrieves the text value, however the following
SET argument < tb.Enabled = False > does not seem to take effect on
the control, since after the Sub is executed 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 08-22-2007 04:21 PM

Re: Accessing Controls nested in a formview
 
On Aug 22, 10:18 am, "Riki" <r...@dontnagme.com> wrote:
> "RGF" <Raf.Figue...@gmail.com> wrote in message
>
> news:1187716766.697840.217400@22g2000hsm.googlegro ups.com...
>
>
>
> > 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 toaccessthe control properties
> > when embedded inside of aFormViewcontrol.

>
> > 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 aFormviewnestedin
> > 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?

>
> Use FindControl:
>
> CType(FormView1.FindControl("TextBox1"),TextBox).E nabled = false;
>
> --
>
> Riki


Riki, thanks for the feedback, I tried your suggestion, and it seems
that I am able to read (Get) the text value from the control without
problem, however, I am not able to "SET" the Enable = False, thus the
control remains editable. Could you suggest a solution with regards
to why the SET function is not working? (see code snip below)

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

'Used the following msg calls to confirm that the return sets
are correct Calendar1 = 9/10/2007 and
'Date.Today = 8/22/2007
MsgBox(CType(FormView1.FindControl("Calendar1"),
Calendar).SelectedDate)
MsgBox(Date.Today)



If (CType(FormView1.FindControl("Calendar1"),
Calendar).SelectedDate) >= Date.Today Then

'Used the following msg call to confirm that the control
to be affected can be read
MsgBox(CType(FormView1.FindControl("MessageTextTex tBox"),
TextBox).Text)

'The following arguments sets the state of the control
CType(FormView1.FindControl("MessageTextTextBox"),
TextBox).Enabled = False

'used the following to force the formview to remain in the
edittemplate
e.KeepInEditMode = True
End If


End Sub

End Class


RGF 08-24-2007 04:22 AM

Re: Accessing Controls nested in a formview
 
On Aug 22, 11:21 am, RGF <Raf.Figue...@gmail.com> wrote:
> On Aug 22, 10:18 am, "Riki" <r...@dontnagme.com> wrote:
>
>
>
> > "RGF" <Raf.Figue...@gmail.com> wrote in message

>
> >news:1187716766.697840.217400@22g2000hsm.googlegr oups.com...

>
> > > 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 toaccessthe control properties
> > > when embedded inside of aFormViewcontrol.

>
> > > 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 aFormviewnestedin
> > > 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?

>
> > Use FindControl:

>
> > CType(FormView1.FindControl("TextBox1"),TextBox).E nabled = false;

>
> > --

>
> > Riki

>
> Riki, thanks for the feedback, I tried your suggestion, and it seems
> that I am able to read (Get) the text value from the control without
> problem, however, I am not able to "SET" the Enable = False, thus the
> control remains editable. Could you suggest a solution with regards
> to why the SET function is not working? (see code snip below)
>
> 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
>
> 'Used the following msg calls to confirm that the return sets
> are correct Calendar1 = 9/10/2007 and
> 'Date.Today = 8/22/2007
> MsgBox(CType(FormView1.FindControl("Calendar1"),
> Calendar).SelectedDate)
> MsgBox(Date.Today)
>
> If (CType(FormView1.FindControl("Calendar1"),
> Calendar).SelectedDate) >= Date.Today Then
>
> 'Used the following msg call to confirm that the control
> to be affected can be read
> MsgBox(CType(FormView1.FindControl("MessageTextTex tBox"),
> TextBox).Text)
>
> 'The following arguments sets the state of the control
> CType(FormView1.FindControl("MessageTextTextBox"),
> TextBox).Enabled = False
>
> 'used the following to force theformviewto remain in the
> edittemplate
> e.KeepInEditMode = True
> End If
>
> End Sub
>
> End Class


I fixed the issue by adding the code into the FormView Prerender
event, now the controls are set correctly based on the conditional
statements I added.

Thanks for the hint!



All times are GMT. The time now is 02:01 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.