自定义 Web 控件,ITemplate 无法识别
希望这很简单,我创建了一个扩展 System.Web.UI.WebControls.Repeater 的自定义 Repeater 控件。 我已向该控件添加了两个 ITemplate 属性,并在需要时以所需的方式添加它们。 一切都工作得很好,但我在 Visual Studio 中遇到了识别这些新模板的问题。
当我将转发器添加到页面时,例如:
<my:Repeater ID="rpt" runat="server" NewProperty="This works!">
<NewTemplate>The contents go here...</NewTemplate>
</my:repeater>
一切正常(哇!),当我添加属性“NewProperty”时,我添加的属性可以按预期在 Visual Studio 的 Intellisense 中看到(哇!)。 令人烦恼的是,虽然新的 ITemplate 无法通过 Intellisense 获得,但我必须从我对它们存在的了解中回忆起这一点(嘘!)。 新模板还带有“问题”下划线,并显示以下消息:
验证(XHTML 1.0 Transitional):不支持元素“newtemplate”。
无论如何,这都不是一个主要问题,因为编译时自定义转发器可以工作并且模板的行为符合其需要,它更多的是一个如果能解决这个烦恼就太好了。
谢谢你的帮助!
史蒂夫
Hopefully an easy one, I have created a Custom Repeater control that extends System.Web.UI.WebControls.Repeater. I Have added two ITemplate Properties to this control and add these when required and in the desired manner. Everything is working absolutely fine but I'm having a problem in Visual Studio having these new Templates recognised.
When I add the repeater to the page, e.g:
<my:Repeater ID="rpt" runat="server" NewProperty="This works!">
<NewTemplate>The contents go here...</NewTemplate>
</my:repeater>
Everything is working (woo!) and when I add the attributes 'NewProperty', a property I have added, can be seen in Intellisense in Visual Studio as expected (woo!). Annoyingly though the new ITemplate's are not available via Intellisense and this has to be recalled from my knowledge of them being there (boo!). The new template also has the 'problem' underline with the following message:
Validation (XHTML 1.0 Transitional): Element 'newtemplate' is not supported.
It's not a major issue by any means as when compiled the custom repeater works and the templates behave as they need to, it's more of an annoyance that would be great to sort out.
Thanks for any help!
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XHTML 要求元素名称以小写字母开头。 HTML 不区分大小写,而 XHTML 则区分大小写。
来源:http://www.w3.org/TR/xhtml1/#h- 4.2
为了使该属性可见,您需要将 PersistenceMode 属性添加到您的 ITemplate 属性中,如下所示:
XHTML requires that Element names begin with a Lower Case. HTML is not case sensitive, while XHTML is.
Source: http://www.w3.org/TR/xhtml1/#h-4.2
In order for the property to be visible, you need to add the PersistenceMode attribute to your ITemplate properties as follows: