|
|
|
start date: Tue, 21 Aug 2007 10:19:26 -0700,
posted on: microsoft.public.dotnet.framework.aspnet.webcontrols
back
| Thread Index |
|
1
RGF
|
|
2
Riki
|
|
3
RGF
|
|
4
RGF
|
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
Date:Tue, 21 Aug 2007 10:19:26 -0700
Author:
|
Re: Accessing Controls nested in a formview
"RGF" wrote in message
news:1187716766.697840.217400@22g2000hsm.googlegroups.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).Enabled = false;
--
Riki
Date:Wed, 22 Aug 2007 17:18:22 +0200
Author:
|
Re: Accessing Controls nested in a formview
On 21 ago, 12:19, RGF 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
Date:Wed, 22 Aug 2007 08:24:02 -0700
Author:
|
Re: Accessing Controls nested in a formview
On Aug 22, 10:18 am, "Riki" wrote:
> "RGF" wrote in message
>
> news:1187716766.697840.217400@22g2000hsm.googlegroups.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).Enabled = 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("MessageTextTextBox"),
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
Date:Wed, 22 Aug 2007 16:21:34 -0000
Author:
|
|
|