如果我们在 asp.net 中编写带有结束标记的脚本管理器和作为空标记的脚本管理器,有什么区别
如果我们以这种格式编写带有结束标记的脚本管理器和作为空标记的脚本管理器有什么区别:
<asp:ScriptManager runat="server">
</asp:ScriptManager>
和作为空标记的脚本管理器。
<asp:ScriptManager runat="server"/>
我在一些面试问题的书中发现了这个问题..请给我一些有关它的知识或给我任何链接..
what is difference if we write script manager with end tag and script manager as a empty tag in this format :
<asp:ScriptManager runat="server">
</asp:ScriptManager>
and script manager as a empty tag.
<asp:ScriptManager runat="server"/>
I found this question in some interview question's book.. plez give me some knowledge about it or give me any link..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的示例中,它们是等效的,但您不能将任何子级添加到自关闭版本中,如果您以编程方式执行此操作,则很好。
请注意,这根本不是特定于该控件的,它适用于几乎所有 ASP.Net 控件(有些控件必须有子控件才有效)。例如:
如果您要进行数据绑定或手动将项目添加到代码中的列表,那么这很好,否则您需要在页面中使用
元素...答案是,这只是一种更干净/简洁的方式来编写不需要任何子标签的标签。With your example they are equivalent, with the exception that you cannot add any children to the self-closing version, which is fine if you're doing it programmatically.
Note that this isn't specific to this control at all, it applies to almost any ASP.Net control (some have to have children to be valid). For example:
This is fine if you're databinding or manually adding items to the list in code, otherwise you'd need
<asp:ListItem />
elements in the page...the short answer is it's just a more clean/concise way to write a tag that doesn't need any children.如果您不需要插入任何 javascript,那么使用空标记会使用更少的字节,因为它是完成相同操作的更短方法。
如果您确实需要添加一些 javascript,那么您必须使用“结束标记”版本,因为这是将脚本放在开始标记和结束标记之间的唯一方法。例如:
我自己倾向于使用“空”标签版本,我认为它看起来更整洁,并且不会让源代码变得混乱。
请参阅:http:// /www.wrox.com/WileyCDA/Section/Using-the-ASP-NET-AJAX-ScriptManager.id-305492.html 了解更多详细信息。
哈特哈,
槊
If you don't need to insert any javascript, then using the empty tag uses less bytes since it's a shorter way to do the same thing.
If you do need to add some javascript, then you'll have to use the 'end tag' version, since that's the only way to put script inside... between the opening and closing tags. eg:
I tend to use the 'empty' tag version myself, I think it looks a bit neater and clutters up the source less.
See this: http://www.wrox.com/WileyCDA/Section/Using-the-ASP-NET-AJAX-ScriptManager.id-305492.html for more details.
HTH,
Lance
没有区别,两者完全等效(顺便说一句,无论标签是什么)。
No difference, both are completely equivalent (whatever the tag, by the way).