• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

TextBox property value not saved

In asp.net 3.5, I'm using the textbox below and assign it values on Page_Load.  After assigning values in Page_Load, I see the values are still there on OnPreRender.  The textBoxes dictionary is of type:

Dictionary<SymbolId, PriceHistoryTextBox>

where SymbolId is an enum.  The dictionary contains all of the textboxes on the form.  When I do a postback via button_click, PriceHistoryId is always zero for every textbox.  EnableViewState="true".  Where did the value go?
[DefaultValue(0)]
    public class PriceHistoryTextBox : TextBox
    {
        private int _priceHistoryId = 0;
 
        public int PriceHistoryId { 
            get
            {
                return _priceHistoryId;
            }
            set
            {
                _priceHistoryId = value;
            }
        }
    }
 
//assigned on Page_Load
private void assignTextboxes(List<History> histories)
        {
            resetTextBoxes();
            foreach (History h in histories)
            {
                PriceHistoryTextBox box = textBoxes[(SymbolId)h.SymbolId];
                if (box != null)
                {
                    box.Text = h.ClosingPrice.ToString();
                    box.PriceHistoryId = h.Id;
                }
            }
        }

Open in new window

0
brettr
Asked:
brettr
  • 2
1 Solution
 
David RobitailleAnalyst ProgrammerCommented:
you have to save you textBoxes dictionary is in the session in order to retirve it on post back.
object on the page are "scraped" at each post back.
 
 
 
 
0
 
David RobitailleAnalyst ProgrammerCommented:
i just find i was in the wrong way, my apologies.
For what i understand, you have to manipulate the viewstate, it s not automatic like for serialization
http://www.developer.com/net/asp/article.php/3606741
0
 
brettrAuthor Commented:
You're absolutely right.  Thanks.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now