Content is not allowed between the opening and closing tags for user control(用户控制的开始和结束标签之间不允许有内容)
问题描述
我想建立一个用户控件假设 MyDiv.ascx.此控件呈现 div 标记并在后面执行一些代码,例如添加一些属性等,这在此处无关紧要.问题是我想要用户控件的开始标签和结束标签之间的文本.例如:
I want to build a user control suppose MyDiv.ascx. This control renders the div tag and do few more code behind stuff like adding few attributes etc which is not a matter of concern here. The problem is I want text between the opening and closing tags of the user control. Eg:
文本与其他一些 HTML 标记一起出现在此处.
The text goes here with some other HTML tags.
所以当我做这样的事情时,我在运行网站时遇到了解析错误.VS2008 也警告我说元素的开始和结束标签之间不允许有内容 MyDiv".
So when do something like this I get a parsing error while running the website. Also VS2008 warns me by saying "Content is not allowed between the opening and closing tags for element MyDiv".
问题 1:我可以做这样的事情,即打开之间的文本/标记和用户控件的结束标签?
问题 2:如果是,如何
推荐答案
我相信你只需要对控件应用几个属性:
I believe you just need to apply a couple of attributes to the control:
[ParseChildren(false)]
[PersistChildren(true)]
public class MyDiv : UserControl
{
...
您可能然后需要覆盖 AddedControl
- 我不确定.
You may then need to override AddedControl
- I'm not sure.
这样说 - 这就是我写过的唯一一个用户控件的工作原理:)
Put it this way - that's what works for the one and only user control I've ever written :)
这篇关于用户控制的开始和结束标签之间不允许有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用户控制的开始和结束标签之间不允许有内容


基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01