Accessing Controls nested in a formview

Discussion in 'ASP .Net Web Controls' started by RGF, Aug 21, 2007.

  1. RGF

    RGF Guest

    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
    RGF, Aug 21, 2007
    #1
    1. Advertising

  2. RGF

    Riki Guest

    "RGF" <> wrote in message
    news:...
    > 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
    Riki, Aug 22, 2007
    #2
    1. Advertising

  3. RGF

    RGF Guest

    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
    RGF, Aug 22, 2007
    #3
  4. RGF

    RGF Guest

    On Aug 22, 10:18 am, "Riki" <> wrote:
    > "RGF" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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
    RGF, Aug 22, 2007
    #4
  5. RGF

    RGF Guest

    On Aug 22, 11:21 am, RGF <> wrote:
    > On Aug 22, 10:18 am, "Riki" <> wrote:
    >
    >
    >
    > > "RGF" <> wrote in message

    >
    > >news:...

    >
    > > > 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 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!
    RGF, Aug 24, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Horace Nunley

    accessing formview controls

    Horace Nunley, Aug 28, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,100
  2. Nathan Sokalski
    Replies:
    0
    Views:
    396
    Nathan Sokalski
    Jan 11, 2007
  3. justin

    accessing controls in FormView

    justin, Jul 31, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    462
    justin
    Jul 31, 2007
  4. RGF
    Replies:
    3
    Views:
    4,282
    moneyran
    Jun 23, 2011
  5. Nathan Sokalski

    Accessing the controls in the PagerTemplate when using FormView

    Nathan Sokalski, Jan 11, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    718
    Nathan Sokalski
    Jan 11, 2007
Loading...

Share This Page