By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,306 Members | 1,930 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,306 IT Pros & Developers. It's quick & easy.

Dynamically added TextBox persists old value --> ViewState issue?

P: n/a
Hi all,
In a web form I use a for loop to dynamically add TextBox'es to a page
(one for each item in an input file). I can get the input values and I
can display them in Label's and TextBox'es. That part works. However,
my problem is that the form lets the user choose from input files; the
labels are updated, the textboxes are not. This seems to me like it is
a ViewState issue, I just can't figure out how to fix that...
Apparently the EnableViewState=false statement doesn't do the trick :(

Abbreviated code snippet:
--- EditLanguage.aspx
<asp:DropDownList runat="server" ID="EditLangDDL" AutoPostBack="true"
<asp:DropDownList runat="server" ID="CompareLangDDL"
AutoPostBack="true" />
<asp:Table runat="server" ID="EditTbl" HorizontalAlign="Center" />

--- EditLanguage.aspx.cs
protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
foreach (Language lang in l.Language) {
<snip populate dropdowns>
<snip retrieve dropdown.SelectedValue's>
<snip create object based on SelectedValue> --> So far so good,
debug shows the values are retrieved correctly...

foreach(Resource r in s.Resources) {
TableRow tr = new TableRow();
TableCell tc1 = new TableCell();
TableCell tc2 = new TableCell();
TableCell tc3 = new TableCell();

Label Path = new Label();
Label Compare = new Label();
TextBox Edit = new TextBox();

Path.Text = String.Format("{0}\\{1}", s.Name, r.Tag);
Compare.Text = (str_compare[s.Name, r.Tag] == null) ? r.Value :
str_compare[s.Name, r.Tag].Value;
Edit.Text = (str_edit[s.Name, r.Tag] == null) ? "*** STRING MISSING
***" : str_edit[s.Name, r.Tag].Value;

Edit.EnableViewState = false; // Desperate attempt...


Long story short, this way the TextBox'es maintain their old value upon
a postback, whereas the Label's do reflect the change.
If I change Edit to be a Label, that too reflects change, therefore
eliminating the possibility of erroneous coding/retrieving the wrong
In other words, the fault is purely [or at least, so it seems ;)] with
it being a TextBox, which of course uses ViewState.

Now my question is, what should I change/add/delete to my code to tell
these darned tb's to update their text property?

Thanks in advance,


May 15 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.