Monday, 20 May 2013

How to do required field validation on server side control using Client Validation in Asp.net

How to do required field validation on server side control using Client Validation in Asp.net

Step 1: First open your website first where you want to implement client script

Step 2 : Open you .aspx page

Step 3 :  Create client script on page like below code


<script type="text/javascript">
    function ValidateRequiredField(objTextBox, errorControl) {
           if (objTextBox.value == "") {
                document.getElementById(errorControl).style.display = 'block';
            }
            else {
                document.getElementById(errorControl).style.display = 'none';
            }
        }
 </script>


Step 4 : Add textbox control on page .

Step 5 : Add one property client side property of control  onBlur and add below code


<asp:TextBox ID="txtNum2" runat="server"           onBlur="ValidateRequiredField(this,'requiredtxtNum2')"></asp:TextBox>
    <span id="requiredtxtNum2" style="color: Red; display: none">Please enter number 2 value</span>


No comments:

Post a Comment

Thank you for your interest .