开发者

Basic server control

I'm looking at server controls for the first time, and I've a question about this code:

[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
    get
    {
        String s = (String)ViewState["Text"];
        return ((s == null) ? "[" + this.ID + "]" : s);
    }

    set
    {
        ViewState["Text"] = value;
    }
}

I do not understand why this control returns the [id] or the text that is set. I do not see how this makes any sense. Is this just for demonstration or is there a reason for return开发者_StackOverflow中文版ing the id?

Thanks


It looks like an example that will show the controls ID if the controls .Text property has not been set.

This is a bit of a "debug" procedure to show that the control is actually rendering even though it hasn't got any data set in it's Text property.


Makes no sense to me. If I'm asking for text, then I expect if there is no text to get either an empty string or null.


If there's nothing been set for the Text property, in ViewState with other words, then this.ID gets returned.

There's not really a meaning for it but it'll show some text in the Property pane of Visual Studio and on the designer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜