嵌套母版页 [英] Nested Master Pages

查看:81
本文介绍了嵌套母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用嵌套母版页的第一个是baseMasterPage,其他母版页使用的是masterMasterPage,称为childMasterPage.现在,我有了名为Details的内容页面,该页面已使用childMasterPage作为MasterPageFile.我在baseMasterPage的lavel控件上有一些价值,我想在详细信息页面上访问它,但我无法做到这一点.我可以通过代码在childMasterPage上访问它-
标签lblWelcome = Master.FindControl("Label1")作为标签;
Label2.Text = lblWelcome.Text.ToString();

但不在详细信息页面上.请告诉我如何在详细信息页面上访问它.

I have using nested master pages first one is baseMasterPage which is used by other master page called childMasterPage. Now I have content page called details which have using childMasterPage as a MasterPageFile. i have some value on lavel control on baseMasterPage and i want to access it on details page, But i am not able to do that. I am able to access it on childMasterPage by code--
Label lblWelcome =Master.FindControl("Label1") as Label;
Label2.Text = lblWelcome.Text.ToString();

but not on details page.Please tell me how i can access it on details page.

推荐答案

这听起来像一场噩梦.我从不使用FindControl,这是一个丑陋的技巧.我为页面创建自己的基类,这些基类返回MasterPage属性的强类型值.如果您在两个级别上都这样做,那么this.MasterPage.MasterPage将为您提供类,您应在其中根据需要在控件上公开属性,而不是整个控件.
This sounds like a nightmare. I never use FindControl, that''s an ugly hack. I create my own base classes for my page that return strongly typed values for the MasterPage property. If you do that on both levels, then this.MasterPage.MasterPage will give you your class, where you should expose properties on your controls as needed, not the entire control.


这篇关于嵌套母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆