Creating ascx dynamically and adding controls to it
I am a beginner in asp.net(C#) and stuck in an important point.
I have a dropdown list on my homepage which users select a category. After selecting the category, user will fill a form 开发者_如何学编程which has related controls to that category in it.
As I have many categories, I just want to have single ascx page and adding controls to it dynamically according to the user choice.
For example: One chose Telephone category, he will face a form having drop down lists asking, what brand? what color? And one chose, book category, he will face drop down lists asking which type? howmany pages?
So 1 ascx must do my work at runtime done as I have alot of categories.
I am going to take these criterias from a database table which has CategoryID and Criteria colomns.
And if I can do that, will it be possible to add field validators to these dynamically created controls.
Nearly all controls are drop down list, if this helps.
Any help would be highly appreciated..
Thanks alot
You can add an asp:placeholder Or literal control to your page and then populate all the controls programatically. Altough you will have to take special care to make sure the control state and view state are correct at all times.
Here's an example on how to do it
https://web.archive.org/web/20211020131055/https://www.4guysfromrolla.com/articles/081402-1.aspx
精彩评论