473,378 Members | 1,617 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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...

tc1.Controls.Add(Path);
tc2.Controls.Add(Compare);
tc3.Controls.Add(Edit);
tr.Cells.Add(tc1);
tr.Cells.Add(tc2);
tr.Cells.Add(tc3);
EditTbl.Rows.Add(tr);
}
}
---

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
string.
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,

Chris

May 15 '06 #1
0 4223

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: eSapient | last post by:
I created a web page which contains a form which contains a table. The number of rows for the table are determined dynamically. The first cell of each row contains a HyperLink control and the last...
2
by: Steve Pierce | last post by:
I am having some issues with a runtime dropdownlist in a datagrid. The issue is that I cannot get ViewState to fill the selected index of a runtime dropdown properly on postback. I do not want to...
3
by: keithb | last post by:
My code dynamically adds template fields to a GridView control. Everything seems to work OK, except when updating, because I haven't found a way to reference the dynamically added textboxes....
3
by: OJ | last post by:
Hi, I have added code to run on a button click event which adds usercontrols to an asp:Panel control held in a contentplaceholder defined by the masterpage. for (int x = 0; x <...
1
by: Mike | last post by:
Hi, I am having troubles dealing with dynamically created WebControls. I have this HTML code: <form id="Form1" runat="server" method="post"> <table width="960" align="center"> <tr> <td...
0
by: jburnage | last post by:
I need help in getting the values from a dynamically added user control when a user submits a form. The controls are added to a placeholder and this all works fine - but its looping through the...
1
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
3
by: Randy | last post by:
Can anybody help me to complete the code for a dynamically added textbox? I can get as far as adding the textbox and placing in the right location, but now I need to bind it to a datasource. Here...
8
by: Randy | last post by:
I'm don't even know where to start on this one. I have a form where the user is allowed to add one row at a time to a table via textboxes. Imagine an order with an undefined number of items to be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.