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

Validating 2 textbox controls

Im trying to do a function to validation two textbox controls. I want the
user to enter in text to either txtSurname or txtCompanyName but not both. Is
my logic wrong and if so can someone help me change this to achieve my goal.
Im really terrible at this and am under pressure to get it done so any help
at all would be appreciated.

function ValidateSurnameCompanyEntered(sender, args)
{
var txtSName = document.WebForm2.txtSurname;
var txtCompName = document.WebForm2.txtCompanyName;
args.IsValid = ((txtSName.text.length>0 && !(txtCompName.text.length < 0))
|| txtSName.text.length> 0 && (txtCompName.text.length < 0));
}
Nov 16 '05 #1
3 1314
I'd suggest reading up on programming logic...

From what I've seen, you've got the javascript idea from me, and populating
the IsValid from somewhere else... The IsValid bit is not readible, even
though it makes the function shorter...

Personally I'd do this.

function ValidateSurnameCompanyEntered(sender, args)
{
var SurnameLength = document.WebForm2.txtSurname.text.length;
var CompanyLength = document.WebForm2.txtCompanyName.text.length;

if ( SurnameLength > 0 && CompanyLength == 0 )
{
args.IsValid = true;
}

if ( SurnameLength == 0 && CompanyLength > 0 )
{
args.IsValid = true;
}

// if both or neither then we get here...
args.IsValid = false;
}

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
Im trying to do a function to validation two textbox controls. I want the
user to enter in text to either txtSurname or txtCompanyName but not both.
Is
my logic wrong and if so can someone help me change this to achieve my
goal.
Im really terrible at this and am under pressure to get it done so any
help
at all would be appreciated.

function ValidateSurnameCompanyEntered(sender, args)
{
var txtSName = document.WebForm2.txtSurname;
var txtCompName = document.WebForm2.txtCompanyName;
args.IsValid = ((txtSName.text.length>0 && !(txtCompName.text.length < 0))
|| txtSName.text.length> 0 && (txtCompName.text.length < 0));
}

Nov 16 '05 #2
Would you not use the TextChanged event from each textbox to enable/disable
the other so that there can never be text in both boxes in the first place?

--Liam.

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
Im trying to do a function to validation two textbox controls. I want the
user to enter in text to either txtSurname or txtCompanyName but not both. Is my logic wrong and if so can someone help me change this to achieve my goal. Im really terrible at this and am under pressure to get it done so any help at all would be appreciated.

function ValidateSurnameCompanyEntered(sender, args)
{
var txtSName = document.WebForm2.txtSurname;
var txtCompName = document.WebForm2.txtCompanyName;
args.IsValid = ((txtSName.text.length>0 && !(txtCompName.text.length < 0))
|| txtSName.text.length> 0 && (txtCompName.text.length < 0));
}

Nov 16 '05 #3
This would require a post back.... Over a slow internet connection, this can
be annoying when validating data.

I've been using some internet sites late that are running asp.net, and they
postback for everything, and even though I'm on a broadband connection (be
it 512kb) i find it really annoying.

"Liam McNamara" <re***@newsgroup.net> wrote in message
news:AW*************@news-srv1.fmr.com...
Would you not use the TextChanged event from each textbox to
enable/disable
the other so that there can never be text in both boxes in the first
place?

--Liam.

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
Im trying to do a function to validation two textbox controls. I want
the
user to enter in text to either txtSurname or txtCompanyName but not
both.

Is
my logic wrong and if so can someone help me change this to achieve my

goal.
Im really terrible at this and am under pressure to get it done so any

help
at all would be appreciated.

function ValidateSurnameCompanyEntered(sender, args)
{
var txtSName = document.WebForm2.txtSurname;
var txtCompName = document.WebForm2.txtCompanyName;
args.IsValid = ((txtSName.text.length>0 && !(txtCompName.text.length <
0))
|| txtSName.text.length> 0 && (txtCompName.text.length < 0));
}


Nov 16 '05 #4

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

Similar topics

6
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed...
2
by: Osmosis | last post by:
I have a form with several controls, which all have their validating and validated events in my code. However, if these controls don't get focus, these events don't get called. When my OK...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
7
by: Bruce HS | last post by:
I'd like to call my ancestor Validation Function every time any control on a Win Form generates a Validating or Validated event. I'm using VB. I've extended Textbox, for instance, to have its...
6
by: Ryan | last post by:
I have a windows form that I want to force validation on controls (text boxes) when the user clicks a "Save" button. The only way I've found to do this is to cycle through every control and call...
3
by: TheSteph | last post by:
Hi Experts ! I have a Winform Program in C# / .NET 2.0 I would like to ensure that a value in a TextBox is a valid Int32 when user get out of it (TextBox loose focus)
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
8
by: Peted | last post by:
I have an amazing problem which i think i have no hope of solving Im working with a c# dot net module that is hosted by and runs under a delphi form envrioment. Dont ask me how this insanity has...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.