Try this code.
.aspx code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DemoPage32.aspx.cs" Inherits="DemoPage32" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Quantity :
<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox><br />
Date :
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
<asp:CustomValidator ID="cvValidateDate" runat="server" ErrorMessage="Date must be entered"></asp:CustomValidator><br />
<asp:Button ID="btnValidate" runat="server" Text="Validate"
onclick="btnValidate_Click" />
</div>
</form>
</body>
</html>
C# code
protected void btnValidate_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(txtQuantity.Text))
{
int qty = int.Parse(txtQuantity.Text);
if (qty > 0)
{
if (String.IsNullOrEmpty(txtDate.Text))
{
cvValidateDate.ErrorMessage = "Date must be entered";
cvValidateDate.IsValid = false;
}
}
}
}