Re: Access Controls nested in a FormView

Discussion in 'ASP .Net' started by RGF, Aug 22, 2007.

  1. RGF

    RGF Guest

    On Aug 21, 12:41 pm, rowe_newsgroups <> wrote:
    > On Aug 21, 1:21 pm, RGF <> 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, Aug 22, 2007
    #1
    1. Advertising

  2. 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 <> wrote:
    > > On Aug 21, 1:21 pm, RGF <> 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
    >
    >
    >
    >
     
    =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?=, Aug 22, 2007
    #2
    1. Advertising

  3. RGF

    RGF Guest

    On Aug 22, 2:00 pm, Ladislav Mrnka
    <> 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 <> wrote:
    > > > On Aug 21, 1:21 pm, 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 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
     
    RGF, Aug 23, 2007
    #3
  4. RGF

    moneyran

    Joined:
    Jun 23, 2011
    Messages:
    1
    Object Reference not set to instance of an object ERROR

    I am trying to get textbox values which are inside a formview control. I want to pass these values as parameters in an sql query.

    I have used the Directcast method and the FindControl method but I got this error. I have no idea what it means. Any suggestions anyone? Is my approach wrong?
     
    moneyran, Jun 23, 2011
    #4
    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. Howard

    access inner formview controls

    Howard, Jul 31, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    6,905
    Ray Booysen
    Jul 31, 2006
  2. Replies:
    0
    Views:
    1,178
  3. Chris

    Formview within Formview

    Chris, May 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    567
    Chris
    May 19, 2007
  4. David Thielen

    FormView/Repeater/ Eval(FormView data)

    David Thielen, Jun 16, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    681
    David Thielen
    Jun 16, 2006
  5. RGF

    Accessing Controls nested in a formview

    RGF, Aug 21, 2007, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    364
Loading...

Share This Page