在自建UserControl或者ServerControl过程中我们常常遇到需要调用<tag>Text</tag>中的Text值。如果不指明,asp.net会抛出 Literal Content is not allowed 错误。网上资料不多,最方便的方法是在UserControl类加上属性:
[ParseChildren(true,"<Default Property>")]<Default Property>是Text被指定的Property name。就这么简单。
本文介绍了解决在自定义ASP.NET UserControl时如何正确设置<tag>Text</tag>属性的问题,避免出现LiteralContentisnotallowed错误。通过在UserControl类上使用特性[ParseChildren]并指定<DefaultProperty>属性名称,可以轻松实现这一目标。
在自建UserControl或者ServerControl过程中我们常常遇到需要调用<tag>Text</tag>中的Text值。如果不指明,asp.net会抛出 Literal Content is not allowed 错误。网上资料不多,最方便的方法是在UserControl类加上属性:
[ParseChildren(true,"<Default Property>")]<Default Property>是Text被指定的Property name。就这么简单。

被折叠的 条评论
为什么被折叠?