/////////////////// JS
<script type="text/javascript">
function validate_Input_Highlight() {
for (var i = 0; i < Page_Validators.length; i++) {
var val = Page_Validators[i];
var ctrl = document.getElementById(val.controltovalidate);
if (ctrl != null && ctrl.style != null && (ctrl.value == "" || ctrl.value == "0")) {
if (!val.isvalid) {
ctrl.style.borderColor = '#FF0000';
ctrl.style.backgroundColor = '#fce697';
}
else {
ctrl.style.borderColor = '';
ctrl.style.backgroundColor = '';
}
}
}
}
</script>
====================================HTML
<table>
<tr>
<td>Emp Name
</td>
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="Required_txtName" runat="server" ValidationGroup="TestGrp"
ControlToValidate="txtName" Display="Dynamic" ErrorMessage="*"
ForeColor="Red" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Salary
</td>
<td>
<asp:TextBox ID="txtSalary" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="Required_txtSalary" runat="server"
ControlToValidate="txtSalary" Display="Dynamic" ErrorMessage="*" ValidationGroup="TestGrp"
ForeColor="Red" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Department
</td>
<td>
<asp:DropDownList ID="ddl_Dept" runat="server">
<asp:ListItem Value="0">-- Select --</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="Required_ddl_Dept" runat="server" ValidationGroup="TestGrp"
ControlToValidate="ddl_Dept" Display="Dynamic" InitialValue="0"
ErrorMessage="*" ForeColor="Red" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Sumbit" ValidationGroup="TestGrp" OnClientClick="return VerifyAndSave();" />
</td>
</tr>
</table>
============================ Result
<script type="text/javascript">
function validate_Input_Highlight() {
for (var i = 0; i < Page_Validators.length; i++) {
var val = Page_Validators[i];
var ctrl = document.getElementById(val.controltovalidate);
if (ctrl != null && ctrl.style != null && (ctrl.value == "" || ctrl.value == "0")) {
if (!val.isvalid) {
ctrl.style.borderColor = '#FF0000';
ctrl.style.backgroundColor = '#fce697';
}
else {
ctrl.style.borderColor = '';
ctrl.style.backgroundColor = '';
}
}
}
}
</script>
====================================HTML
<table>
<tr>
<td>Emp Name
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="Required_txtName" runat="server" ValidationGroup="TestGrp"
ControlToValidate="txtName" Display="Dynamic" ErrorMessage="*"
ForeColor="Red" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Salary
<td>
<asp:TextBox ID="txtSalary" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="Required_txtSalary" runat="server"
ControlToValidate="txtSalary" Display="Dynamic" ErrorMessage="*" ValidationGroup="TestGrp"
ForeColor="Red" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Department
<td>
<asp:DropDownList ID="ddl_Dept" runat="server">
<asp:ListItem Value="0">-- Select --</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="Required_ddl_Dept" runat="server" ValidationGroup="TestGrp"
ControlToValidate="ddl_Dept" Display="Dynamic" InitialValue="0"
ErrorMessage="*" ForeColor="Red" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Sumbit" ValidationGroup="TestGrp" OnClientClick="return VerifyAndSave();" />
</td>
</tr>
</table>
============================ Result
No comments:
Post a Comment