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 :)
这篇关于用户控制的开始和结束标签之间不允许有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用户控制的开始和结束标签之间不允许有内容
基础教程推荐
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
