0

I have below label in my aspx page,

<asp:Label ID="lblMessage" runat="server" CssClass="msg"></asp:Label>

When it renders on page, it creates <span>...</span>

Is there anyway, not to generate this span tag?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Nemi Pujara
  • 73
  • 1
  • 7

2 Answers2

3

You could use a literal HTML <label> element:

<label id="lblMessage" runat="server" class="msg">...</label>

Because of the runat="server" you can still access it through the id in the code-behind .cs file.

Drew Kennedy
  • 4,118
  • 4
  • 24
  • 34
  • 2
    This is the lightest answer...but it's still in a tag, it's just a – Steve Barron Apr 08 '16 at 18:16
  • 2
    @SteveBarron This is correct. I was actually under the impression he was after a ` – Drew Kennedy Apr 08 '16 at 18:28
1

The asp:Label control will always create a <span> in this case.

If you want it to not create a span you could use a literal. Lets say you wanted it to be in a div instead you could do this.

<div class="msg"><asp:Literal id="lblMessage" runat="server" /></div>

The literal just outputs the string without any html tags around it.

AndyC
  • 1,325
  • 1
  • 13
  • 23