HtmlEncode: Fix Problems with certain characters
Category: DotNet
Have you ever had a form with a few fields where users can enter data, and realize that apostrophes give you errors?
This is where Server.HtmlEncode and Server.HtmlDecode come in very handy. Not only does this fix apoostrophes but other characters that need to be stored as html in the database so that they display correctly on their way out. Also avoid problems when trying to write to the database.
string encodedTextForDb = Server.HtmlEncode(TextBoxName.Text); // When you want to display the text coming out of your db storage correctly: LabelName.Text = Server.HtmlDecode(dataTable.Name);