防止其他服务器控件作为自定义 ASP.NET 控件的子控件
除了创建自定义 ControlBuilder
类之外,是否有其他方法可以防止将服务器控件作为子控件添加到自定义 ASP.NET 控件中?
例如,假设我正在构建自己的 Panel
控件:
<my:SpecialPanel ID="SpecialPanel1" runat="server">
<!-- Allow valid HTML -->
<input id="tbEmailAddress" type="text" />
</my:SpecialPanel>
我想阻止用户在 SpecialPanel
内添加服务器端控件:
<my:SpecialPanel ID="SpecialPanel1" runat="server">
<!-- WRONG - Throw an Exception -->
<asp:TextBox ID="tbEmailAddress" runat="server" />
</my:SpecialPanel>
有什么建议吗?
Is there a way, other than creating a custom ControlBuilder
class, to prevent server controls from being added as children in a custom ASP.NET control?
For example, let's say I am building my own Panel
control:
<my:SpecialPanel ID="SpecialPanel1" runat="server">
<!-- Allow valid HTML -->
<input id="tbEmailAddress" type="text" />
</my:SpecialPanel>
I want to prevent users from adding server-side controls inside the SpecialPanel
:
<my:SpecialPanel ID="SpecialPanel1" runat="server">
<!-- WRONG - Throw an Exception -->
<asp:TextBox ID="tbEmailAddress" runat="server" />
</my:SpecialPanel>
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以覆盖 Control.AddParsedSubObject方法:
相关资源:
You could override the Control.AddParsedSubObject method:
Related resources: