Answered by:
How to change rendering type of any tag

Question
-
User1439823427 posted
Hi,
Is there any way to change render type of <p> to <span>?
Or change render type of <span> to <div>.
I have an idea about override RenderBeginTag, apart from this is there any other way to do this. Any suggestion client side or server side will appreciate.
Thursday, December 24, 2009 6:55 AM
Answers
-
User-16411453 posted
I remember when I first started out, I had some tags that were being changed at render. Had to do with the render call. But then I discovered that if I just made use of the asp.net controls, the tags always rendered correctly.
A <span> tag is the label control
The <div> tag is the panel control.
To make a <div> tag
Dim panel_Control As Panel
panel_Control = New Panel
With panel_Control
.Width = [Width]
.style.add(HtmlTextWriterStyle.Margin, "0px auto")
End With
Controls.Add(panel_Control)
So to make a span tag in vb and add it to the panel
Dim lbl_Title as Label
lbl_Title = New Label
With lbl_Title.Style.Add(HtmlTextWriterStyle.Color, "Brown")
.Text = "Hey"
End With
panel_Control.Controls.Add(lbl_Title)
To make a <p> tag, use the literal control
Dim lit_Paragraph As LiteralControl
lit_Paragraph = new LiteralControl
With lit_Paragraph
.Text = "<p class=""SalesText"" style=""margin: 10px;"">" _
"This is my message.</p>"
End With
panel_Control.Controls.Add(lit_Paragraph)
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, December 24, 2009 2:09 PM -
User-319574463 posted
Please see the XHTMLFix project at http://xhtmlfix.codeplex.com/
In such as:
#region Render
/// <summary>
/// Initializes the <see cref="T:System.Web.UI.HtmlTextWriter"/> object and calls on the child controls of the <see cref="T:System.Web.UI.Page"/> to render.
/// </summary>
/// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter"/> that receives the page content.</param>
/// <remarks>
/// This routine can be used in base class.
/// </remarks>
protected override void Render(HtmlTextWriter writer)
{
var sb = new StringBuilder();
var sw = new StringWriter(sb, CultureInfo.InvariantCulture);
var testWriter = new HtmlTextWriter(sw);
base.Render(testWriter);
var pageResult = sb.ToString().Replace("<span disabled=\"disabled\"", "<span");
writer.Write(pageResult);
}
#endregionThe rendered HTML is post-processed to fix problems that otherwise would render the page non XHTML compliant. You can adapt that technique.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, December 27, 2009 12:30 PM
All replies
-
User-16411453 posted
I remember when I first started out, I had some tags that were being changed at render. Had to do with the render call. But then I discovered that if I just made use of the asp.net controls, the tags always rendered correctly.
A <span> tag is the label control
The <div> tag is the panel control.
To make a <div> tag
Dim panel_Control As Panel
panel_Control = New Panel
With panel_Control
.Width = [Width]
.style.add(HtmlTextWriterStyle.Margin, "0px auto")
End With
Controls.Add(panel_Control)
So to make a span tag in vb and add it to the panel
Dim lbl_Title as Label
lbl_Title = New Label
With lbl_Title.Style.Add(HtmlTextWriterStyle.Color, "Brown")
.Text = "Hey"
End With
panel_Control.Controls.Add(lbl_Title)
To make a <p> tag, use the literal control
Dim lit_Paragraph As LiteralControl
lit_Paragraph = new LiteralControl
With lit_Paragraph
.Text = "<p class=""SalesText"" style=""margin: 10px;"">" _
"This is my message.</p>"
End With
panel_Control.Controls.Add(lit_Paragraph)
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, December 24, 2009 2:09 PM -
User-319574463 posted
Please see the XHTMLFix project at http://xhtmlfix.codeplex.com/
In such as:
#region Render
/// <summary>
/// Initializes the <see cref="T:System.Web.UI.HtmlTextWriter"/> object and calls on the child controls of the <see cref="T:System.Web.UI.Page"/> to render.
/// </summary>
/// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter"/> that receives the page content.</param>
/// <remarks>
/// This routine can be used in base class.
/// </remarks>
protected override void Render(HtmlTextWriter writer)
{
var sb = new StringBuilder();
var sw = new StringWriter(sb, CultureInfo.InvariantCulture);
var testWriter = new HtmlTextWriter(sw);
base.Render(testWriter);
var pageResult = sb.ToString().Replace("<span disabled=\"disabled\"", "<span");
writer.Write(pageResult);
}
#endregionThe rendered HTML is post-processed to fix problems that otherwise would render the page non XHTML compliant. You can adapt that technique.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, December 27, 2009 12:30 PM -
User1439823427 posted
Thanks for your help.
Monday, December 28, 2009 6:31 AM