Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 20th, 2005, 04:07 AM
Authorized User
 
Join Date: Dec 2004
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default textbox validation in c#

Hi
I am completely new to c# .so i am just into basics.
just now i am beginning to work with windows forms

now i have to add a text box and a insert button
now when iam entering the text it should be inserted when the button is clicked.
now wht i need is that when the text box is empty and when i clicked the button , it should show a message saying that textbox is empty

I Think this is very smalll problem. But as iam new, pls guide me to do it .

d h o l
__________________
SureShot
  #2 (permalink)  
Old July 20th, 2005, 09:47 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You need to test the length of the text in the textbox
Your textbox has a 'Text' attribute, as well as others.
The Text is of the type 'string' and strings have many attributes, one of wich is Length.
You need to test that Length is greater than zero.
So if your Textbox is called TextBox1, in the onclick event of the button you test like so.

if(TextBox1.Text.Length <= 0)
{
//Show the message
MessageBox.Show("You Messaage");
}
else
{
//Do whatever else you wanted to do
}

I have ot used C# windows for a while so Im not sure syntax is exact, especially the messagebox.show bit.
But that should be a start.

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
  #3 (permalink)  
Old July 20th, 2005, 09:49 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Actually it should be <= not <
I've edited the post


======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
  #4 (permalink)  
Old July 22nd, 2005, 05:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Since you are into .Net already you can also use Required Field Validator class here.

Regards
Ankur Verma


Similar Threads
Thread Thread Starter Forum Replies Last Post
TextBox entry validation thillai Visual Basic 2005 Basics 6 February 20th, 2008 07:23 AM
Textbox validation rhd110 .NET Framework 2.0 1 March 28th, 2007 02:49 PM
TextBox Validation Brettvan1 VB.NET 2002/2003 Basics 1 June 23rd, 2005 08:58 AM
Textbox Validation phudong3da Dreamweaver (all versions) 2 May 9th, 2005 02:47 PM
validation on textbox noor ASP.NET 1.0 and 1.1 Basics 2 May 4th, 2005 02:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.