Link to home
Start Free TrialLog in
Avatar of vickytaurus
vickytaurus

asked on

ASP.NET Label control to render text as <p> tag instead of <span>

I want a label control to render text as <p> tag instead of <span>.
I tried to create a server control inheriting label control as mention in the article below
https://www.experts-exchange.com/questions/21634031/Server-control-to-render-text-within-p-tags.html

But it does not work, the control is ok i included it in my project but it does not produce the desired result, it still is <span> tag

My code:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls


<DefaultProperty("Text"), ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")>
Public Class ServerControl1
    Inherits System.Web.UI.WebControls.Label

    <Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)>
    Protected  Function get_TagKey() As HtmlTextWriterTag
        If Me.AssociatedControlID.Length <> 0 Then
            Return HtmlTextWriterTag.P
        End If
        Return MyBase.TagKey
    End Function

End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of devlab2012
devlab2012
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daniel Van Der Werken
I'm curious if this will fix it or not:

Public Class ServerControl1
    Inherits Label
    Protected Overrides ReadOnly Property TagKey() As HtmlTextWriterTag
        Get
            If AssociatedControlID.Length > 0 Then
                Return HtmlTextWriterTag.P
            End If
            Return TagKey
        End Get
    End Property
End Class
Avatar of vickytaurus
vickytaurus

ASKER

Dan7el, the code does not help.
I am accepting devlab2012's answer as solution although that was not what i was looking for.

Anyways thanks for the prompt response.