Search This Blog

Wednesday, April 24, 2013

How can HTML Character Encoding in C#


<%@ Page Language="C#" MasterPageFile="~/Admin_1/MasterPage.master" AutoEventWireup="true"
    CodeFile="Destination_Month.aspx.cs" Inherits="Admin_1_d_Month"
    Title="Untitled Page" ValidateRequest="false" %>

String displayed correctly in the browser and not interpreted by the browser as HTML. For example, if a text string contains a less than sign (<) or greater than sign (>), the browser would interpret these characters as the opening or closing bracket of an HTML tag. We can manage by HttpUtility.HtmlEncode(TextBox6.Text) any HTML string in c#.


cmd.Parameters.Add("@e6", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox6.Text);
cmd.Parameters.Add("@e7", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox7.Text);
cmd.Parameters.Add("@e8", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox8.Text);
cmd.Parameters.Add("@e9", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox9.Text);

No comments :