views:

51

answers:

2

I have the following code:

  Dim lStatementText As String
  Dim lStatementString As New System.Text.StringBuilder

  lStatementString.Append(RndRes.Forms.txt_request)
  lStatementString.Append(" ")
  lStatementString.Append("<b><a>")
  lStatementString.Append(Request.ID)
  lStatementString.Append("</a> - <a>")
  lStatementString.Append(Request.Description)
  lStatementString.Append("</a></b> ")
  lStatementString.Append(RndRes.Forms.txt_IsNotYetLoaded)
  lStatementString.Append(". ")
  lStatementString.Append(RndRes.Forms.txt_click)
  lStatementString.Append(" <b><a>")
  lStatementString.Append(RndRes.Forms.txt_here)
  lStatementString.Append(" </a></b> ")
  lStatementString.Append(RndRes.Forms.txt_GetFromDB)

  lStatementText = lStatementString.ToString()

  Dim lLink As New Infragistics.Win.FormattedLinkLabel.UltraFormattedLinkLabel()
  lLink.Value = lStatementText
  lLink.TreatValueAs = FormattedLinkLabel.TreatValueAs.FormattedText
  AddHandler lLink.LinkClicked, AddressOf OnLinkClicked

Where Request.ID, Request.Description and also RndRes.Forms.txt_* are all strings. I want to display the string I build up here in a Infragistics FormattedLinkLabel. The problem is that if any of the strigs from the Request class contains a HTML character, the label is not displayed properly and the HTML encoding is broken. I need to find a function that masks the HTML codes.

+2  A: 

Try Server.HtmlEncode() and Server.HtmlDecode(), http://msdn.microsoft.com/en-us/library/hwzhtkke.aspx

Amit Ranjan
Thanks! The solution you provided is good and that's why I gave you a vote up. But the solution from tdammers was easier and more appropriate for my case and I used that one eventually.
John Paul
+3  A: 

If you don't have an HttpContext object at hand, look at HttpUtility.HtmlEncode:

http://msdn.microsoft.com/en-us/library/73z22y6h.aspx

tdammers
Thank you! this solution worked perfectly.
John Paul