Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi To All

I Want Create a Server Control in VS 2010 that called numeric textbox

a class inherited from textbox but only accept Numeric Value

when you drag this control to page Is Ready To Use

All Codes are in inside Component

I Have 2 Ways
1) Java Script
2) Ajax

You Explain Me :
Which?
and
How?

I am Beginner on this Technology, Please Explain Completely;
Thank To Advance
Posted

1 solution

Hi,

Please find the below code with textbox validation has only numeric value using javascript

JavaScript
<head runat="server">
//Javascript code:
<script type="text/javascript">
    function ValidateCCNum(ccNum) {
                var ccno = ccNum.value;
                if (isNaN(ccno)) {
                    alert("Textbox value should be numeric");
                    ccNum.focus();
                    ccNum.value = null;
                    return false;
                }
                return true;
            }
</script>
</head>



ASP.NET
<%--In Aspx file call this function as below--%>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">

<asp:textbox id="txtCCDNo" onblur="ValidateCCNum(this)" runat="server"> </asp:textbox>

</asp:Content>


Run this code in aspx client page
 
Share this answer
 
v4
Comments
ompcj4u 13-Apr-12 9:52am    
HiTanks

But I Want write this Javascripts code inside Component

a class that inherit from textbox that is numeric (Only Accept Number Character)

when you drag this on page, it's Ready To Use (For Numeric)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900