function validate() { if ((document.getElementById("TextBox1").value)=="") { alert("textbox shouldnot be empty"); }
if(!Page_ClientValidate()) { if( string.IsNullOrEmpty(document.getElementById("TextBox1").value) ) { alert("Here I am"); return false; } }
<form id="form1" runat="server"> <asp:Label ID="lblNameRequired" runat="server" Text="*Name :"></asp:Label> <asp:TextBox ID="txtNameRequired" runat="server" ValidationGroup="Validation"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidatorName" runat="server" ControlToValidate="txtNameRequired" Display="None" ErrorMessage="Name is Required" ValidationGroup="Validation"></asp:RequiredFieldValidator> <br /> <asp:Label ID="lblGenderRequired" runat="server" Text="*Gender :"></asp:Label> <asp:DropDownList ID="ddlGenderRequired" runat="server" ValidationGroup="Validation"> <asp:ListItem Selected="True" Value="-1">--Select--</asp:ListItem> <asp:ListItem Value="0">Male</asp:ListItem> <asp:ListItem Value="1">Female</asp:ListItem> </asp:DropDownList> <asp:CompareValidator ID="CompareValidatorGender" runat="server" ControlToValidate="ddlGenderRequired" Display="None" ErrorMessage="Gender is Required" Operator="NotEqual" ValidationGroup="Validation" ValueToCompare="-1"></asp:CompareValidator> <br /> <asp:Label ID="lblValidation" runat="server" Text="Fields marked with * are required"></asp:Label> <br /> <asp:Button ID="btnValidate" runat="server" Text="Validate Input" ValidationGroup="Validation" /> <br /> <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" ShowSummary="False" ValidationGroup="Validation" /> </form>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)