asp.net textbox text not updating

Discussion in 'ASP .Net' started by sekisho@gmail.com, May 7, 2005.

  1. Guest

    I'm dynamically adding a column of labels and a column of text boxes to
    a panel on a webform, based on data returned from an SQL query, which
    the user builds by selecting options from a few dropdowns and hitting
    the 'Search' button.

    The first column returned is a user name and is added to the panel as a
    label, the second is a number and is added to the label as the text
    property of a textbox, so the user can update it.

    When the webform is first called and 'Search' is clicked it works fine,
    but when the dropdown options are changed and 'Search' clicked again,
    the labels change to the correct values but the textboxes retain their
    previous values. What's even stranger is that I explored the problem by
    creating labels instead of textboxes for the second column, and they
    updated correctly, as did using buttons, so it seems to be an issue
    only with textboxes not updating.

    The code I'm using is pretty basic:

    For i = 0 to dt.Rows.Count() - 1

    Dim newLabel As Label = New Label
    newLabel.Text = dt.Rows(i)(1)
    newLabel.ID = "Label" & i
    Panel1.Controls.Add(newLabel)

    Dim newTextBox As TextBox = New TextBox
    newTextBox.Text = dt.Rows(i)(2)
    newTextBox.ID = "Textbox" & i
    Panel1.Controls.Add(newTextbox)

    Panel1.Controls.Add(New LiteralControl("<BR>"))

    Next

    Where dt is the datatable holding the results of my query, there are
    three columns, an index value, a person's name and a number.

    Does anyone have any idea what is going on?
    , May 7, 2005
    #1
    1. Advertising

  2. David Lloyd Guest

    The following information is from the MSDN documentation and explains the
    issue you are seeing. It relates to the page ViewState. Please see the
    MSDN documentation on ViewState for more information.

    From MSDN documentation:

    If you reinsert controls with each round trip, each generation of
    dynamically created controls will pick up property values from the view
    state of the preceding set of controls. In many cases, you can avoid this
    problem by setting the EnableViewState property of the container control to
    false. In that case, no information about the dynamic controls is saved, and
    there is no conflict with successive versions of the controls.


    --
    David Lloyd
    MCSD .NET
    http://LemingtonConsulting.com

    This response is supplied "as is" without any representations or warranties.


    <> wrote in message
    news:...
    > I'm dynamically adding a column of labels and a column of text boxes to
    > a panel on a webform, based on data returned from an SQL query, which
    > the user builds by selecting options from a few dropdowns and hitting
    > the 'Search' button.
    >
    > The first column returned is a user name and is added to the panel as a
    > label, the second is a number and is added to the label as the text
    > property of a textbox, so the user can update it.
    >
    > When the webform is first called and 'Search' is clicked it works fine,
    > but when the dropdown options are changed and 'Search' clicked again,
    > the labels change to the correct values but the textboxes retain their
    > previous values. What's even stranger is that I explored the problem by
    > creating labels instead of textboxes for the second column, and they
    > updated correctly, as did using buttons, so it seems to be an issue
    > only with textboxes not updating.
    >
    > The code I'm using is pretty basic:
    >
    > For i = 0 to dt.Rows.Count() - 1
    >
    > Dim newLabel As Label = New Label
    > newLabel.Text = dt.Rows(i)(1)
    > newLabel.ID = "Label" & i
    > Panel1.Controls.Add(newLabel)
    >
    > Dim newTextBox As TextBox = New TextBox
    > newTextBox.Text = dt.Rows(i)(2)
    > newTextBox.ID = "Textbox" & i
    > Panel1.Controls.Add(newTextbox)
    >
    > Panel1.Controls.Add(New LiteralControl("<BR>"))
    >
    > Next
    >
    > Where dt is the datatable holding the results of my query, there are
    > three columns, an index value, a person's name and a number.
    >
    > Does anyone have any idea what is going on?
    >
    David Lloyd, May 7, 2005
    #2
    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. Replies:
    0
    Views:
    487
  2. news.rcn.com
    Replies:
    2
    Views:
    1,104
    Roedy Green
    Dec 10, 2007
  3. Nic
    Replies:
    0
    Views:
    1,479
  4. SpaceCake
    Replies:
    0
    Views:
    911
    SpaceCake
    Oct 2, 2009
  5. ErwinP
    Replies:
    1
    Views:
    722
    ErwinP
    Aug 19, 2005
Loading...

Share This Page