如何更改包含页面上的用户控制按钮的文本? [英] How to Change the Text of User Control Button on Containing Page?

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

问题描述

HI,

我有一个包含四个按钮的用户控件.在这四个按钮中,我只想在特定的包含页面上更改一个特定按钮的文本.例如一个按钮的文字是创建"我想在我的包含页面上将此按钮的文本更改为清除".可能吗?请指导我



I have a user control which comprise of four buttons. Of these four buttons, I want to change the text of one particular button only on a particular containing page. e.g. one button''s text is "Create" I want to change the text of this button on my containing page as "Clear". Is it possible? Please guide me

推荐答案

您要使用包含页面中的FindControl方法:

You want to use the FindControl method from the containing page:

Button btn = myUserControl.FindControl("ID_OF_BUTTON") as Button;

if(btn != null)
{
   btn.Text = "Clear";
}


吉姆的解决方案肯定会起作用,但这是另一种解决方法.

在用户控制中:

Jim''s solution will surely work but here is another way to it.

In user control:

public string ButtonLabel
    {
        get
        {
           return ID_OF_BUTTON.Text;
        }
        set
        {
           ID_OF_BUTTON.Text = value;
        }
    }



并在包含页面:



And in the containing page:

NameOfUserControl.ButtonLabel = "Clear";


将该文本写入标签,以便您可以检查label.text,然后
您可以更改
按钮名称为button.text ="DONE"
write that text in a label so that you can check label.text and then
you can change the
button name as button.text="DONE"


这篇关于如何更改包含页面上的用户控制按钮的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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