惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Troy Hunt's Blog
F
Fortinet All Blogs
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
The Register - Security
The Register - Security
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
V
Vulnerabilities – Threatpost
S
Securelist
S
SegmentFault 最新的问题
T
Threat Research - Cisco Blogs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Privacy International News Feed
S
Schneier on Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
GbyAI
GbyAI
Apple Machine Learning Research
Apple Machine Learning Research
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
美团技术团队
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google Online Security Blog
Google Online Security Blog
M
MIT News - Artificial intelligence
U
Unit 42
V
V2EX
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
B
Blog
博客园 - 叶小钗
Attack and Defense Labs
Attack and Defense Labs
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Hacker News: Ask HN
Hacker News: Ask HN
博客园 - Franky
Engineering at Meta
Engineering at Meta
Schneier on Security
Schneier on Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Blog of Author Tim Ferriss
IT之家
IT之家
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
Martin Fowler
Martin Fowler
SecWiki News
SecWiki News

博客园 - 含羞草

Jenkins的pipeline脚本中获取git代码变更用户名和email CentOS7安装配置SonarQube CentOS安装Harbor Gitlab自动触发Jenkins构建项目 CentOS7安装Jenkins Master 解决win7下打开Excel2007,报“向程序发送命令时出现问题”的错误 转:老调重弹:const char*, char const* and char *const WebService:System.InvalidOperationException: 无法生成临时类 PowerBuilder:表中字段的数据长度的修改对数据窗口的影响 转:使用SET NOCOUNT优化存储过程 转:如何使用SQL Server 2005 专用管理员连接(DAC)登录到服务器 四遥量 VS.NET开发环境的WIN FORM中怎样加入ActiveX控件 C# Winform程序如何获取运行路径 转:类型"string"的值无法转换为"System.Drawing.Color" - 含羞草 - 博客园 转: Simple ASP.NET 2.0 Tips and Tricks that You May (or may not) have Heard About (一些简单的、你可能已经知道或者不知道的ASP.NET 2.0技巧) SQL Server 2005 : 服务器不允许远程客户端登录的解决办法 SQL Server 2005 : 清空数据库日志 安装删除服务
Asp.net : 访问嵌套模版页中的控件
含羞草 · 2007-04-19 · via 博客园 - 含羞草

如果要访问的控件位于母版页的 ContentPlaceHolder 控件内部,必须首先获取对 ContentPlaceHolder 控件的引用,然后调用其 FindControl 方法获取对该控件的引用。

在内容页的Page_Load方法中设置嵌套模版页中label控件的Text属性:
首先获取主模版页的ContentPlaceHolder控件的引用,然后再获取要修改的控件的引用。
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ContentPlaceHolder pContent = (ContentPlaceHolder)Page.Master.Master.FindControl("Main");
            if (pContent != null)
            {
                Label pLblTitle = (Label)pContent.FindControl("lbl_title");
                if (pLblTitle != null)
                {
                    pLblTitle.Text = "My Title";
                }
            }
        }
    }

附:
主模版页:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="Master_MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:contentplaceholder id="Main" runat="server">
        </asp:contentplaceholder>
    </div>
    </form>
</body>
</html>

嵌套模版页:
<%@ Master Language="C#" MasterPageFile="~/Master/Default.master" AutoEventWireup="true" CodeFile="Combines.master.cs" Inherits="Master_Combines" %>

<asp:content id="Content_combine" contentplaceholderid="Main" runat="server">
    <asp:Label ID="lbl_title" runat="server" Text=""></asp:Label>
    <asp:contentplaceholder id="Combine" runat="server">
    </asp:contentplaceholder>
</asp:content>

内容页:
<%@ Page Language="C#" MasterPageFile="~/Master/Combines.master" AutoEventWireup="true" CodeFile="StationCombine.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<%@ MasterType VirtualPath="~/Master/Combines.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Combine" Runat="Server">
</asp:Content>