Hello to all
I'm handling the Validating event for one text box.
If something is wrong in user input I show a warning message.
The problem is that if I add [e.Cancel=true] to method the message is
displayed twice (event fired twice).
Without [e.Cancel=true] event is fired once.
if(txtMSG.Length > 0)
{
MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
e.Cancel = true;
}
Can you help me ?
Thank you ! 7 7702
Hi Dan,
Ensure that the focus is set to some other control when moving off text box
control. If the focus is not on some other control than text box but you try
closing the form, this event will be fired twice, since the form performs
the validation again.
Thanks
Mona [GrapeCity]
<da*@msdn.com> wrote in message
news:Op****************@TK2MSFTNGP10.phx.gbl... Hello to all
I'm handling the Validating event for one text box. If something is wrong in user input I show a warning message. The problem is that if I add [e.Cancel=true] to method the message is displayed twice (event fired twice). Without [e.Cancel=true] event is fired once.
if(txtMSG.Length > 0) { MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Cancel = true; }
Can you help me ?
Thank you !
Thank you for your answer !
I don't want to close the form. I want to stop the user moving from TextBox
if enter some invalid data. If I add e.Cancel=true then user can't move to
other control until enter valid data.
Moving to other control is not an option for me.
Dan
"Mona" <mo**@discussions.com> wrote in message
news:uk**************@TK2MSFTNGP10.phx.gbl... Hi Dan,
Ensure that the focus is set to some other control when moving off text box control. If the focus is not on some other control than text box but you try closing the form, this event will be fired twice, since the form performs the validation again.
Thanks Mona [GrapeCity]
<da*@msdn.com> wrote in message news:Op****************@TK2MSFTNGP10.phx.gbl... Hello to all
I'm handling the Validating event for one text box. If something is wrong in user input I show a warning message. The problem is that if I add [e.Cancel=true] to method the message is displayed twice (event fired twice). Without [e.Cancel=true] event is fired once.
if(txtMSG.Length > 0) { MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Cancel = true; }
Can you help me ?
Thank you !
Well, when you change the value of e.Cancel, the Validating event is fired
again. So I think you should change the procedure as follow
if(txtMSG.Length > 0)
{
e.Cancel = true;
MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
<da*@msdn.com> дÈëÏûÏ¢ÐÂÎÅ:Op**************@TK2MSFTNGP10.phx.gbl ... Hello to all
I'm handling the Validating event for one text box. If something is wrong in user input I show a warning message. The problem is that if I add [e.Cancel=true] to method the message is displayed twice (event fired twice). Without [e.Cancel=true] event is fired once.
if(txtMSG.Length > 0) { MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Cancel = true; }
Can you help me ?
Thank you !
Thank you for your answer !
I also tried this but event also fired twice.
Dan
"YUN SHI" <te******@citiz.net> wrote in message
news:uh**************@TK2MSFTNGP14.phx.gbl... Well, when you change the value of e.Cancel, the Validating event is fired again. So I think you should change the procedure as follow if(txtMSG.Length > 0) { e.Cancel = true; MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
<da*@msdn.com> дÈëÏûÏ¢ÐÂÎÅ:Op**************@TK2MSFTNGP10.phx.gbl ... Hello to all
I'm handling the Validating event for one text box. If something is wrong in user input I show a warning message. The problem is that if I add [e.Cancel=true] to method the message is displayed twice (event fired twice). Without [e.Cancel=true] event is fired once.
if(txtMSG.Length > 0) { MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Cancel = true; }
Can you help me ?
Thank you !
SOLVED
My mistake. I manage the enter key in KeyPress event and I doubled this key
by mistake.
Thank you all !
Dan
<da*@msdn.com> wrote in message
news:Op****************@TK2MSFTNGP10.phx.gbl... Hello to all
I'm handling the Validating event for one text box. If something is wrong in user input I show a warning message. The problem is that if I add [e.Cancel=true] to method the message is displayed twice (event fired twice). Without [e.Cancel=true] event is fired once.
if(txtMSG.Length > 0) { MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Cancel = true; }
Can you help me ?
Thank you !
See this
private void txtCode_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
if (txtCode.Text.Length > 5)
{
e.Cancel = true;
MessageBox.Show("The Code should not be more than 5 chars!", "Warning
!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
It works pretty much well. When the text in the txtCode control be more than
5 chars, the messagebox will show only once.
"DanDanDan" <da*@msdn.com> дÈëÏûÏ¢ÐÂÎÅ
:uW**************@TK2MSFTNGP15.phx.gbl... Thank you for your answer !
I also tried this but event also fired twice.
Dan
"YUN SHI" <te******@citiz.net> wrote in message news:uh**************@TK2MSFTNGP14.phx.gbl... Well, when you change the value of e.Cancel, the Validating event is
fired again. So I think you should change the procedure as follow if(txtMSG.Length > 0) { e.Cancel = true; MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
<da*@msdn.com> дÈëÏûÏ¢ÐÂÎÅ:Op**************@TK2MSFTNGP10.phx.gbl ... Hello to all
I'm handling the Validating event for one text box. If something is wrong in user input I show a warning message. The problem is that if I add [e.Cancel=true] to method the message is displayed twice (event fired twice). Without [e.Cancel=true] event is fired once.
if(txtMSG.Length > 0) { MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); e.Cancel = true; }
Can you help me ?
Thank you !
Thank you !
My mistake. I manage the enter key in KeyPress event and I doubled this key
by mistake.
Dan
"YUN SHI" <te*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... See this
private void txtCode_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (txtCode.Text.Length > 5) { e.Cancel = true; MessageBox.Show("The Code should not be more than 5 chars!", "Warning !", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
It works pretty much well. When the text in the txtCode control be more than 5 chars, the messagebox will show only once.
"DanDanDan" <da*@msdn.com> дÈëÏûÏ¢ÐÂÎÅ :uW**************@TK2MSFTNGP15.phx.gbl... Thank you for your answer !
I also tried this but event also fired twice.
Dan
"YUN SHI" <te******@citiz.net> wrote in message news:uh**************@TK2MSFTNGP14.phx.gbl... > Well, when you change the value of e.Cancel, the Validating event is fired > again. So I think you should change the procedure as follow > if(txtMSG.Length > 0) > { > e.Cancel = true; > MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK, > MessageBoxIcon.Exclamation); > } > > > <da*@msdn.com> дÈëÏûÏ¢ÐÂÎÅ:Op**************@TK2MSFTNGP10.phx.gbl ... >> Hello to all >> >> I'm handling the Validating event for one text box. >> If something is wrong in user input I show a warning message. >> The problem is that if I add [e.Cancel=true] to method the message is >> displayed twice (event fired twice). >> Without [e.Cancel=true] event is fired once. >> >> if(txtMSG.Length > 0) >> { >> MessageBox.Show(txtMSG, "Warning !", MessageBoxButtons.OK, >> MessageBoxIcon.Exclamation); >> e.Cancel = true; >> } >> >> Can you help me ? >> >> Thank you ! >> >> > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: DanDanDan |
last post by:
Hello to all
I'm handling the Validating event for one text box.
If something is wrong in user input I show a warning message.
The problem is that if I add to method the message is
displayed...
|
by: Joe |
last post by:
Hello All,
I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton
(SearchButton) server controls. The user can type search text in
SearchTextBox and click SearchButton and...
|
by: Joe |
last post by:
Hi
For a while now I have been finding postings of problems with the
validating event not firing on controls properly. I too had this
problem. The event would fire when clicking on another...
|
by: EdB |
last post by:
I am testing in a TextBox KeyPress event to validate characters in the
TextBox. How do I tell it to abort appending my "e" if I deem the character
invalid. I note that on a Form Closing event, e...
|
by: Dennis |
last post by:
I have a simple form with one button and one text box. In the Form, I create
an array list to track the events by adding a descriptive string item to the
arraylist in each event. I first Click on...
|
by: Bruce D |
last post by:
I have a datagrid (uggg) that I use and create the columns
programmatically...see below.
objCol = New DataGridTextBoxColumn
objCol.MappingName = "amount"
objCol.HeaderText = "Amount"...
|
by: Ian Jewitt |
last post by:
Hi,
I am having a problem where the validating event of a text box is not
always firing. I am using vb.net 2003.
I have an MDI application, one of the child forms contains a tab...
|
by: teddysnips |
last post by:
WINDOWS FORMS
I've a form that has a textbox that allows the user to enter a string.
On the LostFocus event, the textbox formats the string into a preferred
format.
However, if the user...
|
by: Hamed |
last post by:
Hello
I have a Data Entry Form having some controls including a TextBox. When the
user types an entry, I query a table and if it was entered before, I ask the
user (using ShowModal method of a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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: 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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |