about load control dynamic

G

Guest

I add controls dynami

Placeholder1.Controls.Clear();
DropDownList d = new DropDownList()
d.ID="controlID"
Placeholder1.Controls.Add(d)
d.Width=200
BindControl(d)
ViewState["AddControl"] = true

and I reload it in Page_load even

private void Page_Load(object sender, System.EventArgs e

if (ViewState["AddControl"]!= null && (bool)ViewState["AddControl"]

DropDownList d = new DropDownList()
d.ID="controlID"
Placeholder1.Controls.Add(d)


it works well, but if I set control's property and Bind Control before it be added to Placeholder1, for exampl

d.Width=200
BindControl(d)
Placeholder1.Controls.Add(d)

it will lost width and listitem after postbac

can anyone tell me why
 
N

Natty Gur

1) since BindControl isnt one of CLR function can you show the code ?

2) if you use postback make sure that you always create the dropdoenlist
and add it to the place holder, even when the page postback. otherwise
the controll won't add to the page control tree and you won't see your
dynamuc control.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top