This is a simple tip to validate user's input, restricting any dagerious html tagas entering etc.
Download source code for How to validate User inputs
Server.HtmlEncode(txtName.Text));
This code will encode user's input, and it is safe to store into the database.
Example:
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml" >
<
head runat="server">
<title>Untitled Page</title>
</
head>
<
body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
</
body>
</
html>
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = Server.HtmlEncode(TextBox1.Text);//here str is encoded str=123< >>
Response.Write(str);
string str1 = TextBox1.Text;//here str is not encoded str=123< >>
Response.Write(str1);
}


About the Author
Full Name:
avinash tumuluMember Level: Starter
Member Status: Member
Member Since: 10/1/2008 12:12:33 AM
Country: India
Hi every one.... Njoy coding....