如何更改母版页控件的值? [英] How to change the value of a control in a master page?

查看:103
本文介绍了如何更改母版页控件的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何改变一个控件的值如文字在用户控制和用户控制在母版页,我想从内容页更改文字的价值。

How to change the value of a control e.g. Literal in a user control and that User control is in master page and I want to change the value of that literal from content page.

((System.Web.UI.UserControl)this.Page.Master.FindControl("ABC")).FindControl("XYZ").Text = "";

下面是ABC的用户控制和XYZ是文字的控制。

Here ABC is user control and XYZ is Literal control.

推荐答案

最好的办法是通过公共属性来公开的值。

The best solution is to expose the values through public properties.

把下面的内容农行控件中包含 XYZ 控制:

Put the following into your ABC control that contains the XYZ control:

public string XYZText
{
    get
    {
        return XYZControl.Text;
    }
    set
    {
       XYZControl.Text= value;
    }
}

现在你可以从母版页中加入以下属性母版揭露这样的:

Now you can expose this from the Master page by adding the following property to the MasterPage:

public string ExposeXYZText
{
    get
    {
        return ABCControl.XYZText;
    }
    set
    {
       ABCControl.XYZText = value;
    }
}

然后从任意内容页面中使用它,只是做了如下(其中 MP 母版类)

string text = ((MP)Page.Master).ExposeXYZText;
((MP)Page.Master).ExposeXYZText = "New Value";

这篇关于如何更改母版页控件的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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