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

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

Masudur

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
 

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,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top