开发者

Can we set ListDictionary property from the page markup?

private ListDictionary parameters;
public ListDi开发者_Go百科ctionary Parameters
{
    get
    {
        if (parameters == null) parameters = new ListDictionary();
        return parameters;
    }
    set
    {
        if (parameters == null) parameters = new ListDictionary();
        parameters = value;
    }
}

can i set such property in the markup of ASP.NET page? and how?

i mean something like <uc1:CustomControl Parameters="?"


Use [System.ComponentModel.Category("Settings")], then a property will appear in markup IntelliSense

I think you need a workaround because all values in markup are strings so you need to parse them into your specific class:

<uc1:CustomControl Parameters="foo,bar" />

[Category("Settings")]
public string Parameters
{
    set
    {
        var arr = String.Split(",", value).Select(p => p.Trim());
        if (parameters == null) parameters = new ListDictionary();
        foreach (string p in arr)
            parameters.Add(p);

    }
}

or use inline (aka code block), e.g.:

<%= new ListDictionary { "foo", "bar " } %>


You can write this statement in the code block IMHO.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜