473,406 Members | 2,259 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.

Validation on TextBox

hi,

I am fresher in C# coding in .Net.

i have been given a task of validation of 2 Text boxes.
here is details : -
we have a screen called Employee Qualification Details where Employee can update his Qualification Details.
now for BE or Software Engineer Student, if they have any GPA, code is working however if there is Score we need to put a validation on "Out of" Text box which is optional.

please help me to how to put validation on "Out of" Text Box when user enters any numerical value in "score" text box.

Thanks in advance
Vandy
Mar 29 '10 #1

✓ answered by VandanaMestri

@VandanaMestri
hi,

thanks for the help, have written the below code pls verify

Validation - if Score Text box value entered is numeric, then out of also should be in numeric.

Expand|Select|Wrap|Line Numbers
  1. try
  2.         {
  3.             //checks both textbox should be numerice if one box is numeric
  4.             int OutOf_Entered = int.Parse(txtOutOf.Text);
  5.             int Score_Entered = int.Parse(txtScore.Text);
  6.             //string score = string.Equals(txtScore.Text);
  7.             if (Score_Entered == OutOf_Entered)
  8.             {
  9.                 errMessage.Append(CommonConstants.NEW_LINE + CommonConstants.OUT_OF_NUMERIC_VALIDATION);
  10.                 flag = false;
  11.             }
  12.  
  13.         }
  14.         catch (RaveHRException rex)
  15.         {
  16.             LogErrorMessage(rex);
  17.         }
  18.         catch (Exception ex)
  19.         {
  20.             // Supress you error message here
  21.         }

6 3214
GaryTexmo
1,501 Expert 1GB
A google search can typically turn up a lot of helpful information. For example, that's how I found this link :)

http://www.java2s.com/Tutorial/CShar...validation.htm

You may also want to look into RegEx validation.
Mar 29 '10 #2
tlhintoq
3,525 Expert 2GB
Or not use a textbox at all. Use a numericupdown with the min and max values within your range. No you don't have to validate because its not possible to enter in a bad value.

Or do an "if...else" construct on the text.changed event, or on the textbox.exit event.

There are lots of ways to handle this if you stop, consider and experiment a bit.

Bytes has a policy regarding assisting students with their homework.

The short version is that the volunteers here can't help you with schoolwork.
A) We don't know what material you have and have not learned in class.
B) We don't know the guidelines you must follow.
C) In the long run giving you the answers actually short changes your education.

Hint 1: Try hitting Google with terms of your programming language and primary terms of what you want to do. For example "C# custom events" or "VB datagrid Excel". I've found this to be a very effective tool.
Hint 2: Your text book
Hint 3: Your instructor
Hint 4: Posting guidelines regarding homework assignments.
Mar 29 '10 #3
@VandanaMestri
hi,

thanks for the help, have written the below code pls verify

Validation - if Score Text box value entered is numeric, then out of also should be in numeric.

Expand|Select|Wrap|Line Numbers
  1. try
  2.         {
  3.             //checks both textbox should be numerice if one box is numeric
  4.             int OutOf_Entered = int.Parse(txtOutOf.Text);
  5.             int Score_Entered = int.Parse(txtScore.Text);
  6.             //string score = string.Equals(txtScore.Text);
  7.             if (Score_Entered == OutOf_Entered)
  8.             {
  9.                 errMessage.Append(CommonConstants.NEW_LINE + CommonConstants.OUT_OF_NUMERIC_VALIDATION);
  10.                 flag = false;
  11.             }
  12.  
  13.         }
  14.         catch (RaveHRException rex)
  15.         {
  16.             LogErrorMessage(rex);
  17.         }
  18.         catch (Exception ex)
  19.         {
  20.             // Supress you error message here
  21.         }
Mar 30 '10 #4
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 30 '10 #5
thanks for your suggestion.

Regards
Vandana
Mar 31 '10 #6
tlhintoq
3,525 Expert 2GB
If this is for a Windows Forms application, you might also like to look at the ErrorProvider component. I use it quite often. The flashing little red exclamations next to each field the user got wrong along with an explanation of why seems to work nicely for my user demographic.

http://msdn.microsoft.com/en-us/libr...rprovider.aspx
Mar 31 '10 #7

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

Similar topics

3
by: Rick | last post by:
I have an interesting problem when I run the following code in Netscape (7.02) vs. IE. This page works great in IE and all my controls bring up the validation summary dialog box if the required...
7
by: A.M | last post by:
Hi, I have a validation control in my page that upon any invalid data, it disables all buttons in the page. basicly i don't have any postback in the page if the validator finds any error. How...
0
by: Boltar | last post by:
Hello, I am trying to use a CustomValidator control to perform client-side validation via a server callback. I have an example below that validates if a textbox contains an odd number. I...
1
by: Arpan | last post by:
I have a Web Form in my ASPX page which makes use of Web controls & incorporates validation controls. This is the code snippet that does the needful: <form runat=server> NAME:<asp:TextBox...
2
by: Tim Frawley | last post by:
Source code attached indicates my problem with validation and a button bar save button. Fill the Textbox with some text then tab off the control. The message box will display the text in the...
1
by: Buddy Ackerman | last post by:
I don't know what the problem is. I have a form with several controls that need to be validated, I put a validation group in every form control, every validatoino control, the submit button and...
2
by: winnie_us99 | last post by:
Hi All, I am trying to do validation on my text field before going to the next page to create a user. It doesn't look like the next button will fire any validation. Am I missing something? Can...
12
by: Dabbler | last post by:
I need to insure that at least one of three phone number fields has a value (requiredfield) but I'm not sure of a way to implement this without server side logic. Is there a way to use the...
6
by: Jon Paal | last post by:
validation doesn't fire what's missing ????? /////// ---- code -----/////////////////////////// Sub btnSubmit_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) 'Handles...
4
by: HenrikL | last post by:
Hi. I have a textbox that have a binding on it with converter and validationrules. When a validation error ouccur the foreground of the textbox will change to red cause it has a style.triggers...
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: 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:
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.