Hi yeti,
Refer the below sample.
HTML
<div>
<table>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox ID="txtName" runat="server" />
</td>
</tr>
<tr>
<td>
Age
</td>
<td>
<asp:TextBox ID="txtAge" runat="server" />
</td>
</tr>
<tr>
<td>
Address
</td>
<td>
<asp:TextBox ID="txtAddress" runat="server" />
</td>
</tr>
<tr>
<td>
Phone No
</td>
<td>
<asp:TextBox ID="txtPhoneNo" runat="server" />
</td>
</tr>
<tr>
<td>
Occupation
</td>
<td>
<asp:TextBox ID="txtOccupation" runat="server" />
</td>
</tr>
<tr>
<td>
Gender
</td>
<td>
<asp:RadioButtonList runat="server" ID="rblGender">
<asp:ListItem Text="Male" />
<asp:ListItem Text="Female" />
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
Race
</td>
<td>
<asp:DropDownList ID="ddlRace" runat="server">
<asp:ListItem Text="Select" />
<asp:ListItem Text="India" />
<asp:ListItem Text="Chinese" />
<asp:ListItem Text="Malay" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Button Text="Submit" runat="server" OnClick="SaveClick" ValidationGroup="ValidateClick" />
</td>
</tr>
</table>
<br />
<asp:CustomValidator ID="cvApplicantRegister" ErrorMessage="" SetFocusOnError="true"
runat="server" Display="Dynamic" OnServerValidate="cvRegister_ServerValidate"
ValidationGroup="ValidateClick" ont-Bold="False" Font-Italic="True" Font-Strikeout="False"
ForeColor="Red"></asp:CustomValidator>
</div>
Code
protected void cvRegister_ServerValidate(object sender, ServerValidateEventArgs args)
{
if (string.IsNullOrEmpty(txtAddress.Text.Trim()))
{
Message("Address is Required!");
txtAddress.Focus();
args.IsValid = false;
}
else if (string.IsNullOrEmpty(txtPhoneNo.Text.Trim()))
{
Message("Phone No is Required!");
txtPhoneNo.Focus();
args.IsValid = false;
}
else if (rblGender.SelectedIndex == -1)
{
Message("Please select gender");
args.IsValid = false;
}
else if (ddlRace.SelectedIndex == 0)
{
Message("Please select race");
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
private void Message(string control)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "Required", "alert('" + control + "')", true);
}
protected void SaveClick(object sender, EventArgs e)
{
if (Page.IsValid)
{
}
}