473,406 Members | 2,371 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,406 software developers and data experts.

Need help! I need to add lead zeros to a textbox

I have a simple text box called txtrefnum, if the user enters a number
length less than 9 characters long than I need to have lead zeros
added to it. Does anyone know how to do this? I couldn't find anything
online on the subject...

<asp:TextBox id="txtRefNum" runat="server"></asp:TextBox>

I thought I could use a validator for the process and make the user
add the zeros, but of course that is a big no-no! Please help!!

Thanks!
Nov 18 '05 #1
2 1566
Do you want to do it on clien side or server side ?

on server side it is simple :

If txtRefNum.Text.Length < 9 Then
Dim zeros as String = ""
Dim index as Integer = 0
For index = txtRefNum.Text.Length To 8
zeros &= "0"
Next
txtRefNum.Text = zeros & txtRefNum.Text
End If

Regards
Martin

"Teep" <ti********@nav-international.com> wrote in message
news:e5*************************@posting.google.co m...
I have a simple text box called txtrefnum, if the user enters a number
length less than 9 characters long than I need to have lead zeros
added to it. Does anyone know how to do this? I couldn't find anything
online on the subject...

<asp:TextBox id="txtRefNum" runat="server"></asp:TextBox>

I thought I could use a validator for the process and make the user
add the zeros, but of course that is a big no-no! Please help!!

Thanks!

Nov 18 '05 #2
No need to write your own Pad() method, there's a String.PadLeft()
method built into .NET. Check here for examples:

http://msdn.microsoft.com/library/de...dlefttopic.asp

That article demonstrates an easier / cleaner way to accomplish this
task. An example:

<snip>
string temp = txtRefNum.Text.PadLeft(9, '0');
</snip>

This should be what you're looking for, Teep.
Martin Marinov wrote:
Do you want to do it on clien side or server side ?

on server side it is simple :

If txtRefNum.Text.Length < 9 Then
Dim zeros as String = ""
Dim index as Integer = 0
For index = txtRefNum.Text.Length To 8
zeros &= "0"
Next
txtRefNum.Text = zeros & txtRefNum.Text
End If

Regards
Martin

"Teep" <ti********@nav-international.com> wrote in message
news:e5*************************@posting.google.co m...
I have a simple text box called txtrefnum, if the user enters a number
length less than 9 characters long than I need to have lead zeros
added to it. Does anyone know how to do this? I couldn't find anything
online on the subject...

<asp:TextBox id="txtRefNum" runat="server"></asp:TextBox>

I thought I could use a validator for the process and make the user
add the zeros, but of course that is a big no-no! Please help!!

Thanks!



Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
0
by: python-help-bounces | last post by:
Your message for python-help@python.org, the Python programming language assistance line, has been received and is being delivered. This automated response is sent to those of you new to...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
2
by: John Baker | last post by:
I find it highly annoying that MS Access tries to go online when I want to look at the help files. Is there a way to configure it so it just looks at my local helpfiles when I hit F1?
27
by: Bruce Dodds | last post by:
I recently started using Access 2003 for the first time. I wanted to pass on some comments about the Help system to Access MVPs who frequent this board. I'm doing this in the hope that some of...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.