Asp.net Response.Write inside an ascx / aspx file
<%if (CanRemove) Response.Write("<b>"+ProductName+"</b>"); %>
This code amazes me as ugly. More specifically, every time I see a Response.Write call inside an ascx or aspx file, I get a suspicion that I'm doing something wrong. Perhaps this is due to the fact that I previously worked with XSLT and noticed that when everything is done correctly, an element is rarely needed <xsl:text>to generate html. I feel this interferes with my ability to read code when my html code is hidden inside a block <% %>.
Is this what I need to get used to Asp.Net or is there a better way to do this?
, Literal control Text Page_Load OnLoad .
protected void Page_Load(object sender, EventArgs e)
{
if (CanRemove)
{
myLiteral.Text = "<b>ProductName</b>"
}
}
System.Web.UI.WebControls.Literal control Mode, :
- PassThrough - ;
- Encode - , HTML ( ).
- Transform - Unsupported markup language elements are removed from the contents of the control. If the Literal control is displayed in a browser that supports HTML or XHTML, the content of the control does not change.
Check the MSDN online documentation for class literal reference