用户控制的开始和结束标签之间不允许有内容

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 :)

这篇关于用户控制的开始和结束标签之间不允许有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)