Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Accessing Controls nested in a formview

Reply
Thread Tools

Accessing Controls nested in a formview

 
 
RGF
Guest
Posts: n/a
 
      08-21-2007
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

 
Reply With Quote
 
 
 
 
Riki
Guest
Posts: n/a
 
      08-22-2007
"RGF" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
RGF
Guest
Posts: n/a
 
      08-22-2007
On 21 ago, 12:19, RGF <(E-Mail Removed)> 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

 
Reply With Quote
 
RGF
Guest
Posts: n/a
 
      08-22-2007
On Aug 22, 10:18 am, "Riki" <(E-Mail Removed)> wrote:
> "RGF" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed) 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

 
Reply With Quote
 
RGF
Guest
Posts: n/a
 
      08-24-2007
On Aug 22, 11:21 am, RGF <(E-Mail Removed)> wrote:
> On Aug 22, 10:18 am, "Riki" <(E-Mail Removed)> wrote:
>
>
>
> > "RGF" <(E-Mail Removed)> wrote in message

>
> >news:(E-Mail Removed) 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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Access Controls nested in a FormView RGF ASP .Net 3 06-23-2011 08:43 PM
accessing controls in FormView justin ASP .Net 0 07-31-2007 07:08 PM
Accessing the controls in the PagerTemplate when using FormView Nathan Sokalski ASP .Net 0 01-11-2007 06:19 AM
Accessing the controls in the PagerTemplate when using FormView Nathan Sokalski ASP .Net Datagrid Control 0 01-11-2007 06:19 AM
accessing formview controls Horace Nunley ASP .Net 1 08-28-2006 05:02 AM



Advertisments