简体   繁体   English

防止在ASP.NET Web窗体中自动关闭html标签

[英]Prevent self closing html tags in ASP.NET Web Forms

I'm learning ASP.NET Web Forms and I'm wondering if it's possible to prevent self closing tags when the html code is generated. 我正在学习ASP.NET Web窗体,并且想知道在生成html代码时是否有可能防止自闭标签。 For instance, if I create an input element, it will self close. 例如,如果我创建一个输入元素,它将自动关闭。 How can I prevent this? 我该如何预防?

Here is the code I'm referring to: 这是我指的代码:

<asp:TextBox id="txt1" runat="server"></asp:TextBox>

Thank you! 谢谢!

Edit: I recently installed Visual Studio 2013 Ultimate and this is what I found: 编辑:我最近安装了Visual Studio 2013 Ultimate,这是我发现的内容:

  • Tools > Options > Text Editor > HTML > Advanced > XHTML coding style 工具>选项>文本编辑器> HTML>高级> XHTML编码样式
    • change from True to False True变为False

And then: 接着:

  • Tools > Options > Text Editor > HTML (Web Forms) > Formatting > Tag Specific Options > Default Settings > Client tag does not support contents > Closing tag 工具>选项>文本编辑器> HTML(Web窗体)>格式>标记特定选项>默认设置>客户端标记不支持内容>关闭标记
    • change from Self-closing tag to No closing tag 自动关闭标签更改为无关闭标签

However, <asp:TextBox runat="server"></asp:TextBox> still gives me <input type="text" /> in the compiled HTML5 code. 但是, <asp:TextBox runat="server"></asp:TextBox> <input type="text" />在已编译的HTML5代码中仍为我提供<input type="text" /> The result I want is <input type="text"> . 我想要的结果是<input type="text">

So if anyone knows how to accomplish this, I would appreciate it. 因此,如果有人知道如何实现这一目标,我将不胜感激。 Thanks! 谢谢!

Follow this link. 点击链接。 Surely want you need is to 当然,您需要的是

  1. Tools 工具
  2. Options 选项
  3. Text Editor 文本编辑器
  4. HTML HTML
  5. Formatting 格式化
  6. Uncheck the box for Auto insert close tag 取消选中自动插入关闭标签

If you are using Visual Studio 2010, you can go to : 如果您使用的是Visual Studio 2010,则可以转到:

Tools > Options > Text Editor > HTML > Formatting > Tag Specific Options 工具>选项>文本编辑器> HTML>格式>标记特定选项

In here you can change the Default Setting of Client and Server tags to be Seperate / Self-Closing . 在这里,您可以将“客户端和服务器”标签的“默认设置”更改为“ Seperate / Self-Closing

You can also change it for specific elements, ie <img> tags by Finding the img item under Client HTML Tags 您还可以通过在“ Client HTML Tags下找到img项目来更改特定元素(即<img>标记)的值

If you are using Visual Studio 2015, you can go to : 如果您使用的是Visual Studio 2015,则可以转到:

Tools > Options > Text Editor > HTML > Advanced > XHTML Coding Style - False 工具>选项>文本编辑器> HTML>高级> XHTML编码样式-False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM