获取母版页对象的ID在内容页 [英] Get ID of Master Page object in Content Page

查看:157
本文介绍了获取母版页对象的ID在内容页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果母版页有id为LABEL1我怎么控制的内容页编号的标签。该ID不传下来的,所以我不能本质上控制它。例如,如果我有id为内容标签控制,我可以访问它只需键入内容标签code。(无论我做)

If the master page has a label with the id label1 how do I control that id in the content page. The id is not passed down so i can't control it inherently. For example if i have a control with the id contentLabel i can access it code by just typing contentLabel.(whatever i'm doing)

推荐答案

下面有两个选项:

1 :确保您的内容的aspx指定 的MasterType:

1: make sure your content aspx specifies MasterType:    

<%@ MasterType VirtualPath="~/yourMasterPageName.master" %>

这样做可以让你的内容页面知道从母版页会发生什么,给你的智能感知。所以,现在你可以继续在暴露母版页的$ C $标签的Text属性C-后面。

Doing this lets your content page know what to expect from your master-page and gives you intellisense. So, now you can go ahead and expose the label's Text property on the master page's code-behind.

public string ContentLabelText
{
    get { return contentLabel.Text; }
    set { contentLabel.Text = value; }
}

然后,您可以访问您的内容页面的code隐藏页ALA:

Then you can access it in your content page's code-behind page ala:

Master.ContentLabelText = "hah!";

2 :您可以通过访问标签<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.control.findcontrol.aspx\">FindControl()像这样:

or, 2: You can access the label via FindControl() like so:

var contentLabel = Master.FindControl("contentLabel") as Label;

这篇关于获取母版页对象的ID在内容页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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