-1

I have a custom web control having two labels. On the display page I want to modify the text of one of the labels depending on a condition. How to achieve?

4

1 回答 1

0

答案取决于您如何定义控件。如果标签是公共的,您只需通过控件实例访问标签

if(condition)
    mycontrol.label.Text = "Some text";

如果它是私有的,您将需要控件中的公共方法来更改文本,例如

void SetLabelText(string text)
{
    this.label.Text = text;
}

然后调用方法

if(condition)
    mycontrol.SetLabelText("Some text");
于 2012-05-12T20:33:53.250 回答