How does a dynamic control load post back data across post back??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

As we know , the view state is not responsible for having TextBoxes,
CheckBoxes, DropDownLists, and other Web controls remember their values
across postback.

When I dynamically add a DropDownList in the web,and dynamically add the
items in it.

such as:

void Page_Load(Object sender, EventArgs e)
{
DropDownList ddlDynamic = new DropDownList();
ddlDynamic.ID = "ddlDynamic";

form1.Controls.Add(ddlDynamic);

if (!IsPostBack)
{
for (int i=1; i <=3; i++)
ddlDynamic.Items.Add(new ListItem(i.ToString(), i.ToString()));
}

I check the second value of the DropDownList.

when post back ,I can see the dynamically items,and the checked value is
what I have checked.

I know that the viewstate of the DropDownList can be loaded by the method
form1.Controls.Add(ddlDynamic) during post back,but I don't know how does the
check value be loaded during post back.
please help me.
 
gorilla said:
As we know , the view state is not responsible for having TextBoxes,
CheckBoxes, DropDownLists, and other Web controls remember their values
across postback.

When I dynamically add a DropDownList in the web,and dynamically add the
items in it.

such as:

void Page_Load(Object sender, EventArgs e)
{
DropDownList ddlDynamic = new DropDownList();
ddlDynamic.ID = "ddlDynamic";

form1.Controls.Add(ddlDynamic);

if (!IsPostBack)
{
for (int i=1; i <=3; i++)
ddlDynamic.Items.Add(new ListItem(i.ToString(), i.ToString()));
}

I check the second value of the DropDownList.

when post back ,I can see the dynamically items,and the checked value is
what I have checked.

I know that the viewstate of the DropDownList can be loaded by the method
form1.Controls.Add(ddlDynamic) during post back,but I don't know how does the
check value be loaded during post back.
please help me.


--->>>>"I know that the viewstate of the DropDownList can be loaded by
the method
form1.Controls.Add(ddlDynamic) during post back,"

if your checked value is already selected then what is the
problem....???

---->>>>"but I don't know how does the check value be loaded during
post back."

i dont get it loading the same control with same id did all to save
and persists the values....
if you want to do some business with the value just subscribe the
SelectedIndexChanged event of dropdown list.

Thanks
Masudur
 
Back
Top