473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Number Text Box in C# - Pls help

11
Hi all,
pls help me as i have been stuck for the past 4 days with the number alone text box that i am using in my asp.net web design.

I need to alert the user once the focus of this txtbox is lost, with a msg box.

I am using C# and my javascript code is:


function CheckValue()
{
if (isNaN(document.getElementById("txtNumber"))
{
alert("Please enter numeric values only.");
return false;
}
}

I tried to get the id of the txtbox using
alert(document.getElementById("txtNumber"));
But the alert shows null. How do i pass the control to the javascript function?


my asp.net code is :

<asp:TextBox ID="txtNumber" runat="server"
Width="31px" ToolTip="1 to 100 - numbers only" MaxLength="3" ></asp:TextBox>



my C# code in the Page is :

protected void Page_Load(object sender, EventArgs e)
{
txtNumber.Attributes.Add("onblur", "CheckValue();");

}

Please help...
Feb 20 '07 #1
4 1867
hi i am giving you the code in vb script
1) take 1 custom validator control
2) set propeties controltovalidate - textbox id you are validating
error message , text,give the validation function - f1
3) now add a new item vb script file (.vbs)
in that type the below code
function f1(s,args)
dim myvar,mycheck
myvar = args.value
mycheck= IsNumeric(MyVar)
if mycheck = true then
args.Isvalid= true
else
args.Isvalid= false
end if
end function
4) finally in your page's(where the text box was presented) html view ,in <head> tag write
<script language="VBScript"></script>
I hope it will help you
Feb 20 '07 #2
kenobewan
4,871 Expert 4TB
Have you resolved the problem?
Feb 22 '07 #3
wertqt
21
hi,
im not too sure what u want but im currently working on the textbox restricting numerical values only.
This is what i written in C#.Net :
Expand|Select|Wrap|Line Numbers
  1.     Expand|Select|Wrap|Line Numbers
  •  
  •     
  •  
  • string AllowChar = @"^(\d{10})$"; 
  •  
  • if (textBox1.Length == 3 && Regex.IsMatch(textBox1.Trim(), AllowChar))
  •  
  • {
  • ..................
  • }
  • else
  • {
  • MessageBox.Show("Serial Number must be 3 characters in length and in numerical form.",
  •                 this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  •  
  • {
  •  
  •     
  •  
  •  
  • Be reminded to add this at the top of the .cs file :

    Expand|Select|Wrap|Line Numbers
    1. using System.Text.RegularExpressions;
    i hope this will help u.
    Feb 22 '07 #4
    MariaJC
    11
    Have you resolved the problem?
    hi

    thanx

    it has been resolved


    rgds
    Mar 17 '07 #5

    Sign in to post your reply or Sign up for a free account.

    Similar topics

    3
    by: Jim Davidson | last post by:
    Here's what I'm trying to do: I have a string with 30 numbers in it. I want to generate a random number between 0 an 30, go to that position in the string and get that number. Here is the code...
    79
    by: Klaus Bonadt | last post by:
    In order to protect software from being copied without licence, I would like to use something like a key, which fits only to the current system. The serial number of the CPU or the current...
    3
    by: brad.goldberg | last post by:
    Hey All, I know this has been addressed in a few different conversations but none are exactly what I am trying to do, bear with me I am an access Newbie. Basically I have a form that assigns...
    1
    by: brad.goldberg | last post by:
    2 Part question for you all, seems kinda tricky to me, but many of you are access gods compared to myself. Here's the deal... I have a label on my form called Run Number: Next to it I have a...
    4
    by: Orchid | last post by:
    How can I change a Date datatype to a Number datatype? For example, I want a date 10/31/2006 to show 1031 as Number datatype. But I don't want it becomes 39021. What formula should I use? ...
    19
    Frinavale
    by: Frinavale | last post by:
    Filtering user input is extremely important for web programming. If input is left unfiltered users can input malicious code that can cripple your website. This article will explain how to make...
    8
    by: Elfae | last post by:
    I have searched high and low for a sample for this, and I just can't find any. Sorry for the length! Background Information The issue revolves around setting up a system-generated increase in...
    0
    by: hennas | last post by:
    Basically i want to design a membership Name and Telephone List form using the following command buttons. Edit Add New; Update; Delete; Cancel; Save; Clear, and Exit
    4
    by: darith | last post by:
    Hi all, I want to know code in vb.net to get number of selected text in MS Word. how can we write? Please help me. I need it urgent. in textbox we just write textbox.selectedtext so we can get...
    2
    by: alwaali | last post by:
    Hi I need help please This is my project and i need a help to solve it with you A page of text is to be read and analyzed to determine number of occurrences and locations of different words. The...
    0
    by: Charles Arthur | last post by:
    How do i turn on java script on a villaon, callus and itel keypad mobile phone
    0
    by: emmanuelkatto | last post by:
    Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
    1
    by: Sonnysonu | last post by:
    This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
    0
    by: Hystou | last post by:
    There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
    0
    marktang
    by: marktang | last post by:
    ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
    0
    Oralloy
    by: Oralloy | last post by:
    Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
    0
    jinu1996
    by: jinu1996 | last post by:
    In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
    0
    by: Hystou | last post by:
    Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
    0
    tracyyun
    by: tracyyun | last post by:
    Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

    By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

    To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.