.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

valicate textbox to accept only numeric value

Posted By:      Posted Date: September 11, 2010    Points: 0   Category :ASP.Net
Hi all,  I have a asp.net webform created using c#. my text box is of type: <asp:textbox id="txtqanum" runat="server">private void txtqanum_TextChanged(object sender, System.EventArgs e) { }   it has only textchanged property. I want user to entered values between  0,1.....9. and if they entered anything else I want to show a message about invalid input. How can I accomplish this? Please help me. Thank You,

View Complete Post

More Related Resource Links

Validating Textbox for Numeric Values

I want to validate a textbox that only a numeric currency value can be put into it, for example 0.00. I thought the following code was correct but it doesnt seem to wrk, its causing an error on my page and when I remove it the page is fine, it doesn't actually give exact details of the error on the page just says "syntax error" in the browser that is all.<asp:CustomValidator runat="server" ErrorMessage="Please enter a numeric value for Night Rate in the format of 0.00" ID="NightRateNum" ControlToValidate="txtNightRate" Text="*" ClientValidationFunction="^\d+(\.\d\d)?$"></asp:CustomValidator>Would appreciate if any can tell me where I went wrong Thanks

Unable to fetch text from a textbox with numeric up-down extender

I have a textbox with numeric updown extender.I want the text of the textbox.I have written code in code file is String a=txtHour.Text//  Source FIle COde<asp:TextBox ID="txtHour" runat="server" ReadOnly="True" Width="45"                     Style="text-align:center" Height="20px"></asp:TextBox>                                       <cc1:NumericUpDownExtender ID="NumericUpDownExtenderHr" runat="server"                     Enabled="True"                     Minimum="00" Maximum="23"                    TargetControlID="txtHour" Width="40">                </cc1:NumericUpDownExtender>

Numeric Up Down Extender overlaps textbox


<asp:Label ID="lblMinutes" runat="server" Text="Minutes :"></asp:Label>

<asp:TextBox ID="txtMinutes" runat="server" Height="20px" Width="45px"
                    Style="text-align:center" CssClass="txtstyle"></asp:TextBox>

<cc1:NumericUpDownExtender ID="txtMinutes_NumericUpDownExtender" runat="server"
                    Enabled="True" Maximum="59"
                    Minimum="00" RefValues="" ServiceDownMethod=""
                    ServiceDownPath="" ServiceUpMethod="" Tag="" TargetButtonDownID=""

All TextBox controls in ASP.NET UpdatePanel won't accept any input after post-back


 My code behind is VB.NET. I use ASP.NET UpdatePanel like the following. However, after the post-back, all textbox in UpdatePanel won't accept any input, except when I move the mouse over and click on the TextBox.

  • Here's why I use UpdatePanel:

    During the post-back, after inserting data into DB, set all TextBox text property to String.Empty

    After the form is submitted, the Panel pStudent should be refresh , not the entire page

    and the TextBox txtId is set in focus again.

It's very strange that this happened to me today. I used UpdatePanel before many time I never had such problem.

Can anyone show me why  all TextBox controls in UpdatePanel won't accept any input after the post-back even though the textbox is focused , only when you move mouse click in them? 

    <asp:UpdatePanel ID="upPOS" runat="server">
            <asp:Panel ID="pStudent" runat="server" CssClass="InContentInfoLight" 
        DefaultButton="btnSubmit" GroupingText="Cafeteria - POS">
                <br />
                <div class ="divleftcolumn-six">
                    ID Number :
                    <asp:TextBox ID

VB 2010 - Currency Textbox will not accept pennies (anything after decimal)


I have several textboxes with an Advanced Data Binding of "Currency" with "Null value = 0.00" and "Decimal Places = 2".  The textboxes perform financial calculations, but when you put a penny amount (regardless of dollar amount), the textbox will lock up and not allow you to exit the program or click on any other textbox.

If I go into the 'Advanced Data Binding' property of any of the textboxes, then I change the 'Data Source Update Mode' to "Never", I can then click out of the textbox. It does not allow me to save, however.

Why is this happening? Is there a better way to have a currency textbox?

Thanks in advance.

Textbox Editable GridView in ASP.NET

This article describes how I made a fully editable gridview in C# using ASP.NET 2. The idea is that the GridView looks and works like an Excel spreadsheet. You see all the cells in the table, and you can edit any of the cells you like, and they are automatically updated (i.e. saved to the database). This is very often how people expect data tables to work in web pages, and I've often seen people clicking in vain on un-editable gridview cells, somehow expecting to edit them, and not understanding that they need to click an Edit button at the end of the row.

Highlighting Rows with TextBox OnFocus

In another article I explained that how you can make the rows of the GridView control clickable and highlight them when they are clicked. In this article I will explain that how you can highlight the GridView rows when you focus on the TextBox which is contained inside the GridView control.

Custom Editing Behavior for DataGridView TextBox Columns

For various reasons I'm using a DataGridView instead of a ListView, and while configuring the DataGridView to look like a ListView wasn't much of a problem, there's one thing that got on my nerves, which is the behavior of textbox cells in edit mode: It is much too easy to leave the edit mode accidentally, simply by pressing the cursor keys at the wrong time. For example when the text caret is positioned behind the last character of the textbox cell content, and you press the right arrow key

Editable Gridview with Textbox, CheckBox, Radio Button and DropDown List

This is an example of an editable gridview containing different ASP.NET controls. When user wants to edit values in gridview, she/he can use these controls to edit existing values in Gridview Edit Mode.

Using the Code

watermark textbox using Ajax control

This is pretty simple compared to jquery. Since we need refer a dll only. we dont want any script for this. we just include that reference into our website.

How to take value of bound field of grid in a variable or in a textbox.


How to take value of bound field of grid in a variable or in a textbox.

 I m using this code in .aspx page for grid.

<asp:GridView ID="Grd_Mprocess" runat="server" AutoGenerateColumns="False"

                      Width="100%" AllowPaging="True"


                      AllowSorting="True" PageSize="5"  >

                 <RowStyle CssClass="odd" />


<asp:BoundField HeaderText="DOC_TYPE_PK" DataField="DOC_TYPE_PK"  Visible="true" >


  <asp:TemplateField HeaderText="DOC TYPE ID" Visible="true">  &nbs

Textbox in ItemTemplate inside Gridview, unable to get the value


Hi. I have a itemtemplate inside a gridview.

<asp:TemplateField HeaderText="Enter OTP">
                            <asp:Label ID="Label2" runat="server"
                                style="font-family: Arial, Helvetica, sans-serif; font-size: x-small"
                                Text="PIN Num:"></asp:Label>
                            &nbsp;<asp:TextBox ID="txtPIN" runat="server" Height="21px" Width="100px"></asp:TextBox>

pass value from textbox to action, formcollection best way here?


Hi I'm building a e-commerce store and on quantity of product I'm going with a textbox. I thought I would ask how would you do this? a viewmodel to use a strongly typed textbox or just get the value of the textbox from the formscollection passed in to the action?

Thanks for any input

how to get an array of all the asp.net textbox control inside create user wizard control?



How can I get all the textboxes inside a create user wizard control using getElementsByTagName().

Below is my JQuery code:

<script type="text/javascript">
        function addLoadEvent(func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            } else {
                window.onload = function() {

        function prepareInputsForHints() {
            var inputs = document.getElementsByTagName("asp:TextBox");
            for (var i = 0; i < inputs.length; i++) {
                inputs[i].onfocus = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
                inputs[i].onblur = function() {
                    this.parentNode.getElementsByTagName("span")[0].style.display = "none";



<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

how to check a textbox value in jquery?



I want to perform some action when an asp.net textbox value length is greater than 1 character. And for this I wanted to know how to write this check in jquery?

I have created a check like below-

if ($('[id=txtUserInput]').val().length > 2)
{ do some work...} 

But its giving me the following error

$("[id=txtUserInput]").val() is undefined

Can anybody let me know the right way of doing this?



how to bind Dropdownlist based on textbox values



I have one drodownlist which show data based om textbox values...

Let us consider i have 

Select Name from table1 where Type IN(@typ)

here @typ is textbox values

here for example textbox will have some thing like this L1,L2,L3..

How to filter Name based and shown in drodownlist based on this L1,L2,L3(on textbox)..

Help me in this

Saving textbox data to MySql database in asp.net


Hi dear coders

though a very simple question to ask, but please tell me how to save and retrieve data in/from my textboxes to/from database (MYSQL) on submit button click.

i know its a very simple task but i cant make it done, so i request you to please send me some working example link or post any helpful code here in asp.net

i will be highly thankful for any kind help from you geniuses.



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend