| Author: ramana 30 Aug 2008 | Member Level: Bronze | Rating: Points: 6 |
CustomValidator is suitable for u r requirement.Below code is useful to u. .aspx: <form id="form1" runat="server"> <div> <asp:TextBox id="txtProductCode" Runat="server" /> <asp:CustomValidator id="valProductCode" ControlToValidate="txtProductCode" Text="(Invalid product code)" OnServerValidate="valProductCode_ServerValidate" Runat="server" ValidateEmptyText="true"/> <asp:Button id="btnSubmit" Text="Submit" Runat="server" OnClick="btnSubmit_Click" /> </div> </form> .aspx.cs: public void valProductCode_ServerValidate(object source, ServerValidateEventArgs args) { if (args.Value.Length > 0) { args.IsValid = true; } else { txtProductCode.BackColor = System.Drawing.Color.Yellow; args.IsValid = false; } }
|