内容是不是在开始和结束标记的用户控件之间允许 [英] Content is not allowed between the opening and closing tags for user control

查看:203
本文介绍了内容是不是在开始和结束标记的用户控件之间允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个用户控件假设MyDiv.ascx。 该控件呈现div标签,做一些更多的code背后的东西,如增加一些属性,这些不是关注的问题在这里。 问题是我希望用户控件的开始和结束标记之间的文本。例如:

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:我可以做这样的事情,即文/口之间的标记 和结束标记用户控制?

  • Question 1: Can I do something like this i.e. text/markup between opening and closing tags of a user control?

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

这篇关于内容是不是在开始和结束标记的用户控件之间允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆