Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 20th, 2005, 05: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
Reply With Quote
  #2 (permalink)  
Old July 20th, 2005, 10: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.
======================================
Reply With Quote
  #3 (permalink)  
Old July 20th, 2005, 10: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.
======================================
Reply With Quote
  #4 (permalink)  
Old July 22nd, 2005, 06:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 03:49 PM
TextBox Validation Brettvan1 VB.NET 2002/2003 Basics 1 June 23rd, 2005 09:58 AM
Textbox Validation phudong3da Dreamweaver (all versions) 2 May 9th, 2005 03:47 PM
validation on textbox noor ASP.NET 1.0 and 1.1 Basics 2 May 4th, 2005 03:29 AM



All times are GMT -4. The time now is 03:18 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.