我想建立一个用户控件假设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 :)
相关推荐
最新文章