Dynamic Template Column - retaining value on postback

Discussion in 'ASP .Net Web Controls' started by Etrast, Jun 17, 2004.

  1. Etrast

    Etrast Guest

    I am adding dynamic template columns to a datagrid. The template column contains a textbox which the user can edit. When I am rendering it initially, the text in the textbox is bound to a column in the dataset. Everything works fine till this point.

    After the user makes changes to the textbox and submits the page, I am creating the dynamic columns in page_load. The problem I am facing is that when creating the textbox again, I do not have the value that the user put in. Is there any way I can get the value put in by the user when I create the template column again on post back.


    All the articles I have read say the value of the textbox should be in the viewstate and should be assigned to the control when it is created again on postback.

    Any help will be greatly appreciated..
     
    Etrast, Jun 17, 2004
    #1
    1. Advertising

  2. Etrast

    Andy Z Smith Guest

    Etrast,

    Generally the framework should re-populate the controls values from the Form submit values. The viewstate is used to track *changes* in the values so that TextChanged event handlers can function properly.

    The usual problem here is the controls are not being created at the right stage of page processing. There are several good documents describing this process, but generally the Form submit values are re-populated between Page_Init and Page_Load and again after Page_Load. My personal experience is that the earlier you can create the control (in Page_Init) the you will have more luck with the framework finding the right control (IDs tend to get messy here too, make sure you assign explicit ID to dynamic controls you create and assign the same ID when you re-create on post-back) and populating the Form submit value into the CodeBehind (OO) control.

    Be careful you are not wiping out the values during you creation/initialization code. It sounds stupid, but often I do this.

    TextBox oBox = new TextBox();
    oBox.Text = ""; // hmm
    HtmlTableCell oCell = new HtmlTableCell();
    oCell.Controls.Add(oBox);

    REF: http://msdn.microsoft.com/library/d.../en-us/dnaspp/html/aspnet-pageobjectmodel.asp


    REF: http://www.15seconds.com/issue/020102.htm

    Andrew S.

    "Etrast" wrote:

    > I am adding dynamic template columns to a datagrid. The template column contains a textbox which the user can edit. When I am rendering it initially, the text in the textbox is bound to a column in the dataset. Everything works fine till this point.
    >
    > After the user makes changes to the textbox and submits the page, I am creating the dynamic columns in page_load. The problem I am facing is that when creating the textbox again, I do not have the value that the user put in. Is there any way I can get the value put in by the user when I create the template column again on post back.
    >
    >
    > All the articles I have read say the value of the textbox should be in the viewstate and should be assigned to the control when it is created again on postback.
    >
    > Any help will be greatly appreciated..
    >
     
    Andy Z Smith, Jun 17, 2004
    #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. mirin
    Replies:
    1
    Views:
    869
    Mark Rae [MVP]
    Mar 3, 2008
  2. Karthikeyan
    Replies:
    1
    Views:
    331
  3. David Bowey
    Replies:
    2
    Views:
    206
    Nick Stansbury
    Apr 5, 2005
  4. Etrast

    Dynamic Template Column - retaining value on postback

    Etrast, Jun 17, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    325
    Tim_k
    Jun 30, 2004
  5. David Bowey
    Replies:
    2
    Views:
    208
    Nick Stansbury
    Apr 5, 2005
Loading...

Share This Page