How should I do this? <variable containing html>

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

Hey

ASP.NET 2.0

I've added some extra properties to the Profile of users on my site. One of
the new properties is of type "string" and it contain HTML data.... like for
example "<div><small>Test</small></div>"

My problem is that I don't know how to display this property on the page. I
want the value to be displayed as any other html code... I don't want the
user to see "<div><small>Test</small></div>", instead the user shall see
"Test", but he should be able too "<div><small>Test</small></div>" in the
html source....

How should I display this value as html?

Best Regards!

Jeff
 
Jeff,

Check out these methods...they might do the trick for you:

Profile.HtmlVariable = Server.HtmlEncode("<div>Some data</div>");

and to retrieve...

someVariableString = Server.HtmlDecode(Profile.HtmlVariable);

~or simply~

Response.Write(Server.HtmlDecode(Profile.HtmlVariable));

Good luck.

-Brenton
 
easy, all you need to do is place a HTML tag like DIV or SPAN set the id and
runat="server" and in your code just use the property innerHtml so assign
the html code to it

like this:

-----------------------------
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Message.InnerHtml = Server.HtmlEncode("Welcome! You accessed this page
at: " & DateTime.Now)
End Sub

</script>

<html >
<head id="Head1" runat="server">
<title>HtmlContainerControl Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<span id="Message" runat=server></span>
</div>
</form>
</body>
</html>
-----------------------------

--

Bruno Alexandre
København, Danmark

"a portuguese in Denmark"
 
LOL

right Robert, I just copy/paste the example from Help Online Books (VS2k5)
and I never thought that ;-)

--

Bruno Alexandre
København, Danmark

"a portuguese in Denmark"


Robert Haken said:
Do NOT use HtmlEncode method if you don't want the HTML to be encoded to
visible... ;-))


Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz


Bruno Alexandre said:
easy, all you need to do is place a HTML tag like DIV or SPAN set the id
and runat="server" and in your code just use the property innerHtml so
assign the html code to it

like this:

-----------------------------
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Message.InnerHtml = Server.HtmlEncode("Welcome! You accessed this page
at: " & DateTime.Now)
End Sub

</script>

<html >
<head id="Head1" runat="server">
<title>HtmlContainerControl Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<span id="Message" runat=server></span>
</div>
</form>
</body>
</html>
-----------------------------

--

Bruno Alexandre
København, Danmark

"a portuguese in Denmark"
 
Back
Top