about load control dynamic

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
Back
Top