如何访问在内部MasterPage中找到的控件 [英] How to access Controls found in inner MasterPage

查看:53
本文介绍了如何访问在内部MasterPage中找到的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有MasterPage1和MasterPage2,它的母版页是MasterPage1

和名为MyPage的ASP.net页面,其母版页面为MasterPage2,例如:

MasterPage1>>>> MasterPage2>>>>>>>>> MyPage

我想从MyPage访问在MasterPage2中找​​到的控件
我可以访问外部MasterPage中的控件,但是我无法访问内部MasterPage中的控件,尽管我认为这很容易

我尝试过但未与我合作:

Hi guys,

I have MasterPage1 and MasterPage2 that its master page is MasterPage1

and ASP.net page called MyPage its master page is MasterPage2 like that:

MasterPage1 >>>>> MasterPage2 >>>>>>>>>> MyPage

I want to access controls found in MasterPage2 from MyPage
I can access the controls in the outer MasterPage, but the problem i cannot access the controls in the inner MasterPage, Although I thought it easy

I try that but not worked with me:

LinkButton tb = this.Master.FindControl("lbtnContact") as LinkButton;

推荐答案

我认为您应该使用以下代码:
I think you should use following code:
ContentPlaceHolder cp = this.Master.Master.FindControl("MainContent") as   ContentPlaceHolder;
LinkButton lb = cp.FindControl("lbtnContact") as LinkButton;



您的主要(最顶层)母版页具有contentplaceholder,例如:



where your main(topmost) masterpage has a contentplaceholder like:

<asp:contentplaceholder id="MainContent" runat="server" />



希望对您有所帮助.



I hope it will help you.


尝试以下代码:
Try this code:
LinkButton tb = (LinkButton)Master.FindControl("lbtnContact")


祝你好运


Good Luck


请参考 [ ^ ]链接,类似的讨论.这会为您提供帮助.
并且请阅读嵌套的ASP.NET母版页 [
Refer this[^] link for the similar discussion. This will help you.
And please read Nested ASP.NET Master Pages[^], it''ll help you to understand the flow.



--Amit


这篇关于如何访问在内部MasterPage中找到的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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