开发者

ASP.NET:Adding a collection of controls dynamically

here is the req开发者_开发百科uirement:

i have a lable a textbox, and two buttons(+ and - button) on my asp.net page.

ASP.NET:Adding a collection of controls dynamically

so when i click on the plus button it should add the the whole collection of controls to the page(i.e. lable, textbox and two buttons). And when i click on minus button it should remove the collection.

ASP.NET:Adding a collection of controls dynamically

This should go on.meaning whenever i click on any plus button the control collection should get added to the page. I am wondering what will be the best approach to do it.

Any suggestion?


You could use postbacks and add your controls server-side, you could even use ajax to make it more seamless.

If you are going to go this way, remember to re-create your dynamic controls on each postback


If post-backs don't bother you, then just do what you mentioned on server side in response to button click event.
Have some container, add and remove components dynamically, attach your event handlers to events of newly created objects.


Wrap the controls you want to show/hide in a panel. Then in the click event handlers of the buttons set the Visible property of the panel to true or false as you need.

Beware that your + button will need to be outside the panel otherwise you'll never get them back again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜