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

推荐订阅源

T
Threatpost
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
S
SegmentFault 最新的问题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 司徒正美
T
Tailwind CSS Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
PCI Perspectives
PCI Perspectives
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
TaoSecurity Blog
TaoSecurity Blog
云风的 BLOG
云风的 BLOG
C
Cybersecurity and Infrastructure Security Agency CISA
O
OpenAI News
Recorded Future
Recorded Future
GbyAI
GbyAI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Y
Y Combinator Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
量子位
博客园 - 叶小钗
V
Vulnerabilities – Threatpost
F
Full Disclosure
Recent Announcements
Recent Announcements
Vercel News
Vercel News
S
Schneier on Security
H
Heimdal Security Blog
Cisco Talos Blog
Cisco Talos Blog
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
B
Blog RSS Feed
宝玉的分享
宝玉的分享
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
爱范儿
爱范儿
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
N
Netflix TechBlog - Medium
S
Security @ Cisco Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyberwarzone
Cyberwarzone

博客园 - 启明

Web纯前端“旭日图”实现元素周期表 能在多种前端框架下使用的表格控件 控件使用经验-MVP模式+控件封装 最好的Angular2表格控件 跨平台开发的两种方法及其对比 是时候 UWP 了 ! 你的系统也可以拥有“数据透视表”功能! Xamarin 免费了,你能做什么? 使用SQL向SQL Server2005中插入图片 在服务器端修改HTML控件的属性 - 启明 - 博客园 如何调用.Net中的非Public方法 - 启明 - 博客园 IsPostBack深入探讨 ViewState机制由浅入深3 ViewState机制由浅入深2 ViewState机制由浅入深1 web form事件不提交 NDoc简介 如何从开发人员走向架构师(转贴) 195本免费的在线编程类书籍 全是E文
MasterPage和内容页之间数据传递
启明 · 2008-01-26 · via 博客园 - 启明

MasterPage是asp.net 2.0中的一个新东东。具有如下的优点:

1.使用母版页可以集中处理页的通用功能,以便可以只在一个位置上进行更新。
2.使用母版页可以方便地创建一组控件和代码,并将结果应用于一组页。例如,可以在母版页上使用控件来创建一个应用于所有页的菜单。
3.通过允许控制占位符控件的呈现方式,母版页使您可以在细节上控制最终页的布局。
4.母版页提供一个对象模型,使用该对象模型可以从各个内容页自定义母版页。

在实际的使用中内容页要和MasterPage之间进行数据交换。下面介绍一种数据传递的方式。
1、在内容页中增加如下的语句

<%@ MasterType VirtualPath="~/MasterPage.master" %>
VirtualPath的值是MaterMage的路径

2、在MaterPage中定义Public的方法

    public void SetValue(string s)
    {
        this.Label1.Text = s;
    }

    public string GetValue()
    {
        return this.Label1.Text;
    }

SetValue方法用于从内容页向MasterPage传递数据。
GetValue方法用于从MasterPage向内容页传递数据。

3、在内容页中调用MasterPage中的方法
如果没有第1步(创建对母版页的强类型引用),在内容页中看不见MasterPage中的方法

    protected void Button2_Click(object sender, EventArgs e)
    
{
        
//向MasterPage传递值
        Master.SetValue("OK");
        
//从MasterPage获取值        
        string str = Master.GetValue();
    }

4、从MasterPage向内容页传递数据的另外方式
上面的从MasterPage向内容页传递数据是一种拉的方式,比较被动。我们还可以在MasterPage中定义事件,通过事件将数据传递到内容页也可以。

5、FindControl
我们可以在内容页中调用

Master.FindControl(MasterPage中控件ID)来获取MasterPage中的控件。
还可以调用Master.FindControl(MasterPage中的ContentPlaceHolder的控件ID).FindControl(内容页中控件ID)来找到内容页中的控件。