开发者

Dynamically add <asp:content to page, Nested masterpages

开发者 https://www.devze.com 2023-01-19 22:24 出处:网络
I am currently using nested masterpages in my latest asp.net 4.0 project a开发者_如何学Gond i want to change the look and feel dynamically, so the homepage may just be 1 column wide, about us page may

I am currently using nested masterpages in my latest asp.net 4.0 project a开发者_如何学Gond i want to change the look and feel dynamically, so the homepage may just be 1 column wide, about us page may be 2 columns etc.

I am dynamically loading the masterpage dependant on the record selected in the DB (1column.master, 2column.master) on the pre_init event of a static page (Load.aspx) which work succesfully however i need to be able to dynamically add controls to the page in order to get the desired layout.

Is this possible, is there a better way of achieveing this?

Please inform me if you need more information / or have any questions.

Thanks


however i need to be able to dynamically add controls to the page in order to get the desired layout. Is this possible, is there a better way of achieveing this?

Yes it is possible. The tricky thing about adding dynamic controls to ASP.NET webpages (master, content, whatever) is that the controls must be recreated each postback to the server. This is the combersome part. You can't just modify your page by dynamically adding controls, and expect them to exist the next time there is a postback to the server. This includes not only the control but all of its properties like ID, etc.

For some more information take a look to the following link:

Dynamic Web Server Controls and View State:
http://msdn.microsoft.com/en-us/library/hbdfdyh7.aspx

Dynamic Controls in ASP.NET
https://web.archive.org/web/20211020131055/https://www.4guysfromrolla.com/articles/081402-1.aspx

0

精彩评论

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

关注公众号