母版页-> SubMasterPage-> Web表单...在子页面中获取母版页的属性 [英] Masterpage -> SubMasterPage -> Web Form...getting properties of Masterpage in sub pages

查看:124
本文介绍了母版页-> SubMasterPage-> Web表单...在子页面中获取母版页的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我对此提出了一个相关问题,并被告知不要做什么,而不是我应该做什么.

I asked a related question on this yesterday, and was told what not to do, but not what I should do.

我有一个母版页,我将其称为"TheMaster".我有2个子母版页"Sub1"和"Sub2".它们都具有"TheMaster"的母版页指令. Web窗体的母版页伪指令为"Sub1"或"Sub2".这些不是真实姓名.

I've got a master page that I'll call "TheMaster". I've got 2 sub master pages "Sub1" and "Sub2". They both have a Masterpage directive of "TheMaster". Web Forms have a Masterpage directive of "Sub1" or "Sub2". These aren't the real names.

在"TheMaster"中,我找出用户所处的页面,找出他们在Web.sitemap中的位置,并使用它来拥有Web.sitemap节点以及父级和父级的父级(如果有)全部存在.我用它来动态构建导航并突出显示当前页面.

In "TheMaster", I figure out what page the user is on, find out where in the Web.sitemap they are, and using that, I have the Web.sitemap node and the parent and the parent's parent, if they all exist. I use this to build navigation dynamically and highlight the current page.

现在,我们的设计师在此导航中出现了几个位置.顶部导航,子导航,左侧导航和面包屑"样式,显示首页-> parentparentnode-> parentnode->当前页

Now, our designers have several places this navigation appears. Top nav, sub nav, teritiary nav on the left, and a "breadcrumb" style showing home -> parentparentnode -> parentnode -> currentpage

由于布局限制,我无法在"TheMaster"中定义所有这些内容.

I can NOT define all of this in "TheMaster" due to layout constraints.

因此,在"TheMaster"中,找到它们的当前节点,并将其保存为"TheMaster"的公共属性(以及其他一些信息.

So, in "TheMaster", I find their current node, and save that as a public property of "TheMaster" (along with several other pieces of info.

在Sub1中,即使它使用的是"TheMaster"作为母版,也似乎无法从"TheMaster"中找到我的公共财产.

In Sub1, even though it is using "TheMaster" as it's masterpage, it does not appear to be able to find my public properties from "TheMaster".

关于我如何通过这套纸牌一直获取此信息的任何想法?

Any ideas on how I can get this info to be available all the way through this house of cards?

我尝试过

Page.Master.myProp (nope)
Parent.myProp (nope)

我想不出什么办法来使它起作用. "TheMaster"基本上对"Sub1"一无所知,因此我无法在Sub1上设置属性并将其放在树上,并且树下的节点显然对父母无视... ???

I can't think of anyything else to get this to work. "TheMaster" has basically no knowledge of "Sub1", so I can't set a property on Sub1 and have it go down the tree, and the nodes down the tree are apparently oblivious to their parents...???

推荐答案

将父项或Page.Master投射到您的实际MasterPage类.

Cast Parent or Page.Master to your actual MasterPage class.

((MyMaster)Page.Master).myProp // found!

这篇关于母版页-> SubMasterPage-> Web表单...在子页面中获取母版页的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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