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

推荐订阅源

S
Schneier on Security
F
Fortinet All Blogs
B
Blog
GbyAI
GbyAI
P
Proofpoint News Feed
量子位
The Register - Security
The Register - Security
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
B
Blog RSS Feed
WordPress大学
WordPress大学
Recorded Future
Recorded Future
Recent Announcements
Recent Announcements
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
雷峰网
雷峰网
Stack Overflow Blog
Stack Overflow Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Webroot Blog
Webroot Blog
AWS News Blog
AWS News Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The GitHub Blog
The GitHub Blog
爱范儿
爱范儿
O
OpenAI News
月光博客
月光博客
H
Hacker News: Front Page
S
Security Affairs
W
WeLiveSecurity
The Hacker News
The Hacker News
aimingoo的专栏
aimingoo的专栏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Help Net Security
Help Net Security
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
T
The Blog of Author Tim Ferriss
Spread Privacy
Spread Privacy
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
S
Securelist
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
T
Threat Research - Cisco Blogs
M
MIT News - Artificial intelligence
A
About on SuperTechFans

博客园 - hemingchen

MiniProfiler asp.net MVC控制器中返回JSON格式的数据时提示下载 Delphi XE2 新技术说明 (What's new in Delphi XE2)(转载) Microsoft.VisualStudio.Xaml 加载错误 解决 网页如何有效调用exe js parentElement - hemingchen - 博客园 Response.ContentType 详细列表 - hemingchen - 博客园 SQL 2005 开启OpenRowset/OpenDatasource的办法 常用正则表达式 - hemingchen - 博客园 XMLHTTP 保护自己的眼睛 转载 37个Ajax和CSS实现的Tab选项卡切换效果界面 SQL2005附加数据库"失败........无法更新数据库"xxx",因为数据库是只读 - hemingchen - 博客园 .net Access 新增记录后获取自动编号的值 JavaScript 脚本文件编码导致的问题 jquery json简单例子 jquery ajax xml jquery学习 使用面向对象的技术创建高级 Web 应用程序 文章来源:http://msdn.microsoft.com/zh-cn/magazine/cc163419.aspx本文讨论:
asp.net C# 下母版页使用
hemingchen · 2008-08-20 · via 博客园 - hemingchen

1.缓存使用:
 在使用master页面时,不能把高速缓存只应用与master页面,不能把OutputCache指令放到master页面上。如果这么做,在页面的第二次检索时,就会报错。因为应用程序找不到缓存页面.

2.在内容页中编写代码来引用母版页中的属性、方法和控件:

可以在内容页中编写代码来引用母版页中的属性、方法和控件,但这种引用有一定的限制。对于属性和方法的规则是:如果它们在母版页上被声明为公共成员,则可以引用它们。这包括公共属性和公共方法。在引用母版页上的控件时,没有只能引用公共成员的这种限制。

引用母版页上的公共成员

  1. 在内容页中添加 @ MasterType 指令。在该指令中,将 VirtualPath 属性设置为母版页的位置,如下面的示例所示:

    <%@ MasterType virtualpath="~/Masters/Master1.master" %>

    此指令使内容页的 Master 属性被强类型化。

  2. 编写代码,将母版页的公共成员用作 Master 属性的一个成员,如本例中,将母版页名为 CompanyName 的公共属性的值赋给内容页上的一个文本框:

引用母版页上的控件

  • 使用 FindControl 方法,将 Master 属性的返回值用作命名容器。

    下面的代码示例演示如何使用 FindControl 方法获取对母版页上的两个控件的引用(一个 TextBox 控件和一个 Label 控件)。因为 TextBox 控件处在 ContentPlaceHolder 控件的内部,必须首先获取对 ContentPlaceHolder 的引用,然后使用其 FindControl 方法来定位 TextBox 控件。

  • void Page_Load()
        {
        // Gets a reference to a TextBox control inside
        // a ContentPlaceHolder
        ContentPlaceHolder mpContentPlaceHolder;
        TextBox mpTextBox;
        mpContentPlaceHolder =
        (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
        if(mpContentPlaceHolder != null)
        {
        mpTextBox =
        (TextBox) mpContentPlaceHolder.FindControl("TextBox1");
        if(mpTextBox != null)
        {
        mpTextBox.Text = "TextBox found!";
        }
        }
        // Gets a reference to a Label control that not in
        // a ContentPlaceHolder
        Label mpLabel = (Label) Master.FindControl("masterPageLabel");
        if(mpLabel != null)
        {
        Label1.Text = "Master page label = " + mpLabel.Text;
        }
        }