why is ddl.selectedValue not retained in viewstate ?

G

Guest

I try to move textBoxes and ddl dynamically to a ASP:table and everything
works correctly, except that for the ddl's the selectedValue is not retained
(it is for the TextBoxes).
Here is my code:
private void LoadTable()
{
Table1.Rows.Clear();
TableRow r = new TableRow();
TableCell c = new TableCell();
c.Controls.Add(Page.FindControl("TextBox1"));
TextBox1.Visible = true;
c.Controls.Add(Page.FindControl("DropDownList1"));
DropDownList1.Visible = true;
if (tbxHidden.Text == "")
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add("Value1");
DropDownList1.Items.Add("Value2");
DropDownList1.Items.Add("Value3");
}
r.Cells.Add(c);
Table1.Rows.Add(r);
TableDummy.Rows.Clear();
tbxHidden.Text = "IsLoaded";
TableCell cd= new TableCell();
TableRow rd = new TableRow();
cd.Controls.Add(Page.FindControl("tbxHidden"));
rd.Cells.Add(cd);
TableDummy.Rows.Add(rd);
}

Is this a bug ?
 
P

Peter Rilling

You have to populate the list in the Init event. The viewstate is processed
between the Init and Load.
 
J

JIMCO Software

Peter said:
You have to populate the list in the Init event. The viewstate is
processed between the Init and Load.


That's true in part. The part of the lifecycle that is responsible for
maintaining this is the LoadPostData() method of the IPostBackDataHandler
interface. Any control that posts form data (textbox, checkbox, ddl, etc.)
implements IPostBackDataHandler and uses the LoadPostData() method to
maintain state between postbacks.

In other words, this has nothing to do with viewstate. Turn off viewstate
and you will still persist your values via IPostBackDataHandler.

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com

FrontPage add-ins for FrontPage 2000 - 2003
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top