Home
About
Contact
Categories
Classic ASP (30 - Entries)
CSS (1 - Entry)
JavaScript (5 - Entries)
Databases (26 - Entries)
ASP.NET (25 - Entries)
Delphi (6 - Entries)
Windows Server Core (7 - Entries)
VMWare (1 - Entry)
Code Editing Tools (2 - Entries)
Linux (3 - Entries)
Dell Servers (15 - Entries)
Blog Entries
2025 (3 - Entries)
Bug Reports
(Bugs Fixed
CFFCS Coding Source
Please report any errors to the [
Contact
] page. Thank you.
Classic ASP (30)
CSS (1)
JavaScript (5)
Databases (26)
ASP.NET (25)
Delphi (6)
Windows Server Core (7)
VMWare (1)
Code Editing Tools (2)
Linux (3)
Dell Servers (15)
Tools
Format Your SQL Script
Minify your CSS
Resources
[View The Source Code For This Project]
ASP.NET
C#
ASP.NET (C# Version) check if Zip Code exists. If not, show a message.
Live Editing Disabled for Server-Side Example
HTML
Load.aspx
<%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true" CodeFile="Load.aspx.cs" Inherits="Load" %>
Zip Code:
City =
State =
County =
ASP.NET
web.config
database.config
Load.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; // SQLConnection using System.Configuration; // ConfigurationManager public partial class Load : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { ShowZip.Visible = false; } private string ProtectXSS(string SqlString) { SqlString = SqlString.Replace("\'", "\'\'"); // replace single Quotes with Double Quotes SqlString = SqlString.Replace(">", ">"); // replace > with > SqlString = SqlString.Replace("<", "<"); // replace < with < SqlString = SqlString.Replace("(", "("); // replace ( with ( SqlString = SqlString.Replace(")", ")"); // replace ) with ) SqlString = SqlString.Trim(); return SqlString; } protected void Sub_Click(object sender, EventArgs e) { var LessonCon = new SqlConnection(); SqlCommand LessonCMD = new SqlCommand(); string ZC = ProtectXSS(Zip.Text); LessonCon = new SqlConnection(ConfigurationManager.ConnectionStrings["Virtual-Learning"].ConnectionString); LessonCon.Open(); if (ZC.All(char.IsDigit)) { SqlCommand getZip = new SqlCommand("select Zip, City, State, County from ZipTable where Zip=@Zip", LessonCon); getZip.Parameters.Add(new SqlParameter("@Zip", ZC)); SqlDataReader rsZip; rsZip = getZip.ExecuteReader(); if (rsZip.Read()) { ShowZip.Visible = true; Zipcode.Text = rsZip["Zip"].ToString(); City.Text = rsZip["City"].ToString(); State.Text = rsZip["State"].ToString(); County.Text = rsZip["County"].ToString(); } else try { LessonCMD.ExecuteNonQuery(); } catch (Exception ex) { Response.Write("Sorry, there seems to be an issue. Please try entering the Zip Code the proper way and try again."); } finally { rsZip.Close(); LessonCon.Close(); } } else { Response.Write(ZC + "Not a valid number, please enter a Zip Code."); } } }
Preview
Tags
protect our database from XSS and SQL Injection
protect our database from XSS and SQL Injection
protect our database from XSS and SQL Injection
protect our database from SQL Injection
protect our database from SQL Injection
protect our database from SQL Injection
Zip Code lookup form In An ASP.net
Zip Code lookup form In An ASP.net
Zip Code lookup form In An ASP.net
US Zip Code lookup form
US Zip Code lookup form
US Zip Code lookup form
protect our database from XSS Attacks
protect our database from XSS Attacks
C# Zip Code Lookup
C# Zip Code Lookup
C# Protect against SQL Injection
C# Protect against XSS Attacks
C# Parameterized Queries