Custom Web Control - ParseChildren & Resource Objects

Posted by Raybiez on Stack Overflow See other posts from Stack Overflow or by Raybiez
Published on 2010-04-20T16:00:03Z Indexed on 2010/04/20 16:03 UTC
Read the original article Hit count: 230

Filed under:
|

I hope someone can help me. I have the following custom server control:

[ParseChildren(true)]
public class MyControl : WebControl, INamingContainer
{
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public string MyProperty
    {
      get;set;
    }
}

It works perfectly with the following mark-up:

<acme:MyControl runat="sever">
    <MyProperty>Test String</MyProperty>
</acme:MyControl>

But if I try to localise the property string, I get a parse error:

<acme:MyControl runat="sever">
    <MyProperty><%=(string)GetLocalResourceObject("MyResourceKey") %></MyProperty>
</acme:MyControl>

Even if I cast the type, ASP.NET indicates that the property cannot accept controls as children. How should the expression look like if I want to localise it? I can make the property accessible as an attribute of the control's tag, but I prefer the mark-up above, it looks more elegant and clean.

Thanks

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about control