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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
宝玉的分享
宝玉的分享
V
Visual Studio Blog
S
Securelist
P
Palo Alto Networks Blog
A
Arctic Wolf
T
Tor Project blog
P
Proofpoint News Feed
I
InfoQ
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
G
GRAHAM CLULEY
M
MIT News - Artificial intelligence
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Apple Machine Learning Research
Apple Machine Learning Research
S
Secure Thoughts
Cyberwarzone
Cyberwarzone
Blog — PlanetScale
Blog — PlanetScale
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - 【当耐特】
大猫的无限游戏
大猫的无限游戏
腾讯CDC
Latest news
Latest news
Project Zero
Project Zero
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
S
SegmentFault 最新的问题
Schneier on Security
Schneier on Security
C
CERT Recently Published Vulnerability Notes
W
WeLiveSecurity
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LINUX DO - 热门话题
N
News and Events Feed by Topic
PCI Perspectives
PCI Perspectives
C
Cisco Blogs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
The Last Watchdog
The Last Watchdog
人人都是产品经理
人人都是产品经理
GbyAI
GbyAI
Know Your Adversary
Know Your Adversary
U
Unit 42

博客园 - 含羞草

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>