Simple question, difficult to search for (due to the main part of the question being the single letter p
)!
In ASP.NET, <asp:Panel/>
is rendered as a <div></div>
block, <asp:Label/>
is rendered as a <span></span>
block... is there one that renders as <p></p>
block?
It doesn't look like it from MSDN for the WebControl class, but I thought I would ask in case I've missed something obvious.
(I realise the obvious solution is to just use <p runat="server" id="p1"></p>
and use the generic html control class)
Answer: <P> tag is used for giving paragraphs in Asp.Net pages.It starts with <P> and ends with </P>. We can write any static contents inside paragraph tags.It will treat as one paragraph. We can take multiple we want.
I've had exactly the same issue. After I started to use a similar technique Cory uses here, I found an even easier one, that basically does the same and solves your issues. However, it has one benefit when compared with the solution above: you don't have to render the whole control yourself.
Basically all you need to do is the following:
RenderBeginTag()
method. p
. span
in this example).See code below:
public class P : Label
{
public override void RenderBeginTag(HtmlTextWriter writer)
{
writer.RenderBeginTag("p");
}
}
No, there is no built-in control specifically for <p>
. A LiteralControl
or the <p runat="server" />
version you gave are the closest you will get.
You could always create your own control, though. You can create a class that implements WebControl
, and override the Render
method:
protected override void Render(HtmlTextWriter output)
{
output.WriteFullBeginTag("p");
output.Write(this.Text);
output.WriteEndTag("p");
}
There are more instructions on how to write your own server controls here:
And a list of all of the .NET web and server controls here:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With