How to validate User inputs

Posted by in ASP.NET category on for Beginner level | Views : 4203 red flag

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


This code will encode user's input, and it is safe to store into the database.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >

<head runat="server">

<title>Untitled Page</title>



<form id="form1" runat="server">


<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />







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&lt; &gt;&gt;


string str1 = TextBox1.Text;//here str is not encoded str=123< >>





Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: avinash tumulu
Member Level: Starter
Member Status: Member
Member Since: 10/1/2008 12:12:33 AM
Country: India

Hi every one.... Njoy coding....

Login to vote for this post.

Comments or Responses

Posted by: Bhupender.Yadav on: 4/11/2013 | Points: 25
what you exactly want to do???

Login to post response

Comment using Facebook(Author doesn't get notification)