2

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. 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:

  • Tools > Options > Text Editor > HTML > Advanced > XHTML coding style
    • change from True to False

And then:

  • Tools > Options > Text Editor > HTML (Web Forms) > Formatting > Tag Specific Options > Default Settings > Client tag does not support contents > Closing tag
    • 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. The result I want is <input type="text">.

So if anyone knows how to accomplish this, I would appreciate it. Thanks!

2
  • 1) Why? Self-closing tags are perfectly valid tags 2) You can write any kind of tag you want in the aspx file. Are you referring to some control-generated tags? Did you check the various templated controls? Some actual code would help Commented Jan 21, 2014 at 10:20
  • 1. Because I write my html5 code without self closing tags and I don't want any. 2. I've edited the op. Thanks! Commented Jan 21, 2014 at 10:27

3 Answers 3

1

Follow this link. Surely want you need is to

  1. Tools
  2. Options
  3. Text Editor
  4. HTML
  5. Formatting
  6. Uncheck the box for Auto insert close tag
Sign up to request clarification or add additional context in comments.

Comments

0

If you are using Visual Studio 2010, you can go to :

Tools > Options > Text Editor > HTML > Formatting > Tag Specific Options

In here you can change the Default Setting of Client and Server tags to be Seperate / Self-Closing.

You can also change it for specific elements, i.e. <img> tags by Finding the img item under Client HTML Tags

1 Comment

Thank you! I don't have access to VS right now, but this seems to be it.
0

If you are using Visual Studio 2015, you can go to :

Tools > Options > Text Editor > HTML > Advanced > XHTML Coding Style - False

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.