I have a form to generate a report.
On the form are several textboxes and a "Generate" button.
I would like to have the button grayed (not enabled), unless the data in
each of the dependant textboxes is valid.
What is the proper procedure for doing this?
It seems the Validating and Validated events for each control only fire when
it loses focus.
I would like the button to be enabled as soon as the data is valid (before
leaving the control).
Also, how do I "sum up" all the controls into one master enable? 4 2661
Well, the .NET validation strategy is to validate each control as it loses
focus. The reason for this is that in most cases, for a text box, for
example, you don't want to validate in until the user is done typing. Their
partial text is likely to be invalid if it's supposed to meet some sort of
validation requirement, so you don't want there to be an error until after
it loses focus.
In your case, you want to validate as they type and it sounds like you want
to validate all the text boxes.
So, it's fairly simple. For each textbox, add an event handler for
TextChanged. You only need a single method that actually handles it for all
the textboxes, so for each textbox, you'd add that one. For example:
textBox1.TextChanged += new EventHandler(ValidateTextBoxes);
textBox2.TextChanged += new EventHandler(ValidateTextBoxes);
textBox3.TextChanged += new EventHandler(ValidateTextBoxes);
private void ValidateTextBoxes(object sender, EventArgs e)
{
... validate all my textboxes here ...
}
When they're in a valid state, simply enable the button.
That should work. If you need to know which textbox sent the message, simply
cast "sender" to a TextBox
Pete
"Kathy" <katnel20 at hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... I have a form to generate a report. On the form are several textboxes and a "Generate" button. I would like to have the button grayed (not enabled), unless the data in each of the dependant textboxes is valid. What is the proper procedure for doing this?
It seems the Validating and Validated events for each control only fire when it loses focus. I would like the button to be enabled as soon as the data is valid (before leaving the control). Also, how do I "sum up" all the controls into one master enable?
Ok Pete, I'll buy that.
I guess seeing the 2 Validation events and other methods in the control, I
assumed the Framework authors had some sort of "grand scheme" that I was
overlooking.
On a related topic, Java has the concept of a Document model that can be
attached to a textbox which monitors the TextChanged event and limits input
to valid chars. Is there something similar in .NET?
Kathy.
"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message
news:ht********************@giganews.com... Well, the .NET validation strategy is to validate each control as it loses focus. The reason for this is that in most cases, for a text box, for example, you don't want to validate in until the user is done typing. Their partial text is likely to be invalid if it's supposed to meet some sort of validation requirement, so you don't want there to be an error until after it loses focus.
In your case, you want to validate as they type and it sounds like you want to validate all the text boxes.
So, it's fairly simple. For each textbox, add an event handler for TextChanged. You only need a single method that actually handles it for all the textboxes, so for each textbox, you'd add that one. For example:
textBox1.TextChanged += new EventHandler(ValidateTextBoxes); textBox2.TextChanged += new EventHandler(ValidateTextBoxes); textBox3.TextChanged += new EventHandler(ValidateTextBoxes);
private void ValidateTextBoxes(object sender, EventArgs e) { ... validate all my textboxes here ... }
When they're in a valid state, simply enable the button.
That should work. If you need to know which textbox sent the message, simply cast "sender" to a TextBox
Pete "Kathy" <katnel20 at hotmail.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...I have a form to generate a report. On the form are several textboxes and a "Generate" button. I would like to have the button grayed (not enabled), unless the data in each of the dependant textboxes is valid. What is the proper procedure for doing this?
It seems the Validating and Validated events for each control only fire when it loses focus. I would like the button to be enabled as soon as the data is valid (before leaving the control). Also, how do I "sum up" all the controls into one master enable?
Kathy,
Not so much a "document model". You can bind datasets (and datatables and
such) to controls on your form. For limiting input to valid characters, you
pretty much have to do that on your own, if I'm understanding you.
I mean, generally, you'd want to create custom controls that handle
formatting of text, or at least that's what I'd do. For example, if I needed
a control that handled only numeric data (and I planned on re-using it in
the app), I'd derive a class from TextBox that restricted the input. That
kind of stuff is fairly trivial to do.
But then my job is creating custom .NET controls, so I have a tendency
to handle things in that way.
Did you have something else in mind?
Pete
"Kathy" <katnel20 at hotmail.com> wrote in message
news:OU**************@tk2msftngp13.phx.gbl... Ok Pete, I'll buy that. I guess seeing the 2 Validation events and other methods in the control, I assumed the Framework authors had some sort of "grand scheme" that I was overlooking.
On a related topic, Java has the concept of a Document model that can be attached to a textbox which monitors the TextChanged event and limits input to valid chars. Is there something similar in .NET?
Kathy.
"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message news:ht********************@giganews.com... Well, the .NET validation strategy is to validate each control as it loses focus. The reason for this is that in most cases, for a text box, for example, you don't want to validate in until the user is done typing. Their partial text is likely to be invalid if it's supposed to meet some sort of validation requirement, so you don't want there to be an error until after it loses focus.
In your case, you want to validate as they type and it sounds like you want to validate all the text boxes.
So, it's fairly simple. For each textbox, add an event handler for TextChanged. You only need a single method that actually handles it for all the textboxes, so for each textbox, you'd add that one. For example:
textBox1.TextChanged += new EventHandler(ValidateTextBoxes); textBox2.TextChanged += new EventHandler(ValidateTextBoxes); textBox3.TextChanged += new EventHandler(ValidateTextBoxes);
private void ValidateTextBoxes(object sender, EventArgs e) { ... validate all my textboxes here ... }
When they're in a valid state, simply enable the button.
That should work. If you need to know which textbox sent the message, simply cast "sender" to a TextBox
Pete "Kathy" <katnel20 at hotmail.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...I have a form to generate a report. On the form are several textboxes and a "Generate" button. I would like to have the button grayed (not enabled), unless the data in each of the dependant textboxes is valid. What is the proper procedure for doing this?
It seems the Validating and Validated events for each control only fire when it loses focus. I would like the button to be enabled as soon as the data is valid (before leaving the control). Also, how do I "sum up" all the controls into one master enable?
No, I just thought there would be a class in the framework already so I
didn't have to do the "char at a time" validation.
I did a lot of forms in Java and got use to that framework. I just figured
Microsoft would have done the same or at least gone one better.
Thanks for the help.
Kathy.
"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message
news:6e******************************@giganews.com ... Kathy,
Not so much a "document model". You can bind datasets (and datatables and such) to controls on your form. For limiting input to valid characters, you pretty much have to do that on your own, if I'm understanding you.
I mean, generally, you'd want to create custom controls that handle formatting of text, or at least that's what I'd do. For example, if I needed a control that handled only numeric data (and I planned on re-using it in the app), I'd derive a class from TextBox that restricted the input. That kind of stuff is fairly trivial to do.
But then my job is creating custom .NET controls, so I have a tendency to handle things in that way.
Did you have something else in mind?
Pete
"Kathy" <katnel20 at hotmail.com> wrote in message news:OU**************@tk2msftngp13.phx.gbl... Ok Pete, I'll buy that. I guess seeing the 2 Validation events and other methods in the control, I assumed the Framework authors had some sort of "grand scheme" that I was overlooking.
On a related topic, Java has the concept of a Document model that can be attached to a textbox which monitors the TextChanged event and limits input to valid chars. Is there something similar in .NET?
Kathy.
"Pete Davis" <pdavis68@[nospam]hotmail.com> wrote in message news:ht********************@giganews.com... Well, the .NET validation strategy is to validate each control as it loses focus. The reason for this is that in most cases, for a text box, for example, you don't want to validate in until the user is done typing. Their partial text is likely to be invalid if it's supposed to meet some sort of validation requirement, so you don't want there to be an error until after it loses focus.
In your case, you want to validate as they type and it sounds like you want to validate all the text boxes.
So, it's fairly simple. For each textbox, add an event handler for TextChanged. You only need a single method that actually handles it for all the textboxes, so for each textbox, you'd add that one. For example:
textBox1.TextChanged += new EventHandler(ValidateTextBoxes); textBox2.TextChanged += new EventHandler(ValidateTextBoxes); textBox3.TextChanged += new EventHandler(ValidateTextBoxes);
private void ValidateTextBoxes(object sender, EventArgs e) { ... validate all my textboxes here ... }
When they're in a valid state, simply enable the button.
That should work. If you need to know which textbox sent the message, simply cast "sender" to a TextBox
Pete "Kathy" <katnel20 at hotmail.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... I have a form to generate a report. On the form are several textboxes and a "Generate" button. I would like to have the button grayed (not enabled), unless the data in each of the dependant textboxes is valid. What is the proper procedure for doing this?
It seems the Validating and Validated events for each control only fire when it loses focus. I would like the button to be enabled as soon as the data is valid (before leaving the control). Also, how do I "sum up" all the controls into one master enable?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tim Haughton |
last post by:
I've just released an article on using Test Driven Development with C# and
Windows Forms. GUI's are often difficult to test, so I thought it might be
of interest.
The article along with the...
|
by: Frans Bouma |
last post by:
Hello,
It seems VS.NET 2003 locks up itself and the complete shell (mouse locks
also) when entering a breakpoint in a special situation.
Below is the code to reproduce this behavior. It...
|
by: RAJ |
last post by:
hi
plz tell me how to know "how window is going to close"...
i have to right code for X button of forms...
plz telll me
thanks
bye
|
by: honcho |
last post by:
My ASP.NET web application has a flaw that produces false security-violation
alarms.
There are several categories of users for this web site, e.g. Colonels,
Sergeants, Private_1s,
and...
|
by: Mr Newbie |
last post by:
I am using a DataGrid for Edit and Update. However, Im wondering what the
best strategy for client side validation would be as I dont think the
validators can reference the TextBoxes which come up...
|
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...
|
by: Daniela Roman |
last post by:
Hello,
can someone tell me the main differences between the web and windows based
applications?
thank you
|
by: Yohan Blurp |
last post by:
Hello everybody. I'm writing a Perl script managing forms submissions
but encounter some difficulty on a step.
1) User submits a form (using POST method). The page being declared as
cacheable...
|
by: Dan Tallent |
last post by:
In my application I have a form (Customer) that I want to be able to open
multiple copies at once. Within this form I have other forms that can be
opened. Example: ZipCode. When the user enters...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |