.NET: Need To Drop The Span Tag From the Label Control? Use the Literal Control Instead

Have you ever had the need to use a label control, but you don’t need the span tag that the control automatically wraps around the text? Switch your control over to the Literal control instead. It serves the same general purpose as the label control, but will not wrap your output in those pesky span tags.

<code lang="csharp[lines]"><br></br><literal id="myControl" runat="server" text="Some random value"></literal><br></br>

You can then use your normal server side code to the change the value, just as you would the label control:

<code lang="csharp[lines]"><br></br>
myControl.Text = "My new random value"<br></br>


comments powered by Disqus