Monday, 20 May 2013

How to do Textbox numeric validation using Client Script on Server Side Control

How to do Textbox numeric validation using Client Script on Server Side Control

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 IsNumeric(key) {
            var keycode = (key.which) ? key.which : key.keyCode;
            if ((keycode >= 48 && keycode <= 57)) {
                return true;
            }
            // 8 =  backbutton
            // 36 = Home Button
            // 9 = Tab Key
            // 46 =  Delete Button
            else if (keycode == 8 || keycode == 36 || keycode == 9 || keycode == 46)
                return true;
            else {
                return false;
            }
        }
    </script>



Step 4 : Add textbox control on page .

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

<asp:TextBox ID="txtNum1" runat="server" onkeypress="return IsNumeric(event)"></asp:TextBox>

    <asp:TextBox ID="txtNum2" runat="server" onkeypress="return
IsNumeric(event)"></asp:TextBox>


Step 6 : Try to check you code in browser .

No comments:

Post a Comment

Thank you for your interest .