473,837 Members | 1,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextBox Validating event firing twice

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.Lengt h > 0)
{
MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
MessageBoxIcon. Exclamation);
e.Cancel = true;
}

Can you help me ?

Thank you !
Nov 17 '05 #1
7 7795
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******** ********@TK2MSF TNGP10.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.Lengt h > 0)
{
MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
MessageBoxIcon. Exclamation);
e.Cancel = true;
}

Can you help me ?

Thank you !

Nov 17 '05 #2
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**@discussio ns.com> wrote in message
news:uk******** ******@TK2MSFTN GP10.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******** ********@TK2MSF TNGP10.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.Lengt h > 0)
{
MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
MessageBoxIcon. Exclamation);
e.Cancel = true;
}

Can you help me ?

Thank you !


Nov 17 '05 #3
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.Lengt h > 0)
{
e.Cancel = true;
MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
MessageBoxIcon. Exclamation);
}
<da*@msdn.com > 写入消息新闻:Op **************@ TK2MSFTNGP10.ph x.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.Lengt h > 0)
{
MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
MessageBoxIcon. Exclamation);
e.Cancel = true;
}

Can you help me ?

Thank you !

Nov 17 '05 #4
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******** ******@TK2MSFTN GP14.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.Lengt h > 0)
{
e.Cancel = true;
MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
MessageBoxIcon. Exclamation);
}
<da*@msdn.com > 写入消息新闻:Op **************@ TK2MSFTNGP10.ph x.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.Lengt h > 0)
{
MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
MessageBoxIcon. Exclamation);
e.Cancel = true;
}

Can you help me ?

Thank you !


Nov 17 '05 #5
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******** ********@TK2MSF TNGP10.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.Lengt h > 0)
{
MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
MessageBoxIcon. Exclamation);
e.Cancel = true;
}

Can you help me ?

Thank you !


Nov 17 '05 #6
See this

private void txtCode_Validat ing(object sender,
System.Componen tModel.CancelEv entArgs e)
{
if (txtCode.Text.L ength > 5)
{
e.Cancel = true;
MessageBox.Show ("The Code should not be more than 5 chars!", "Warning
!", MessageBoxButto ns.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******** ******@TK2MSFTN GP14.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.Lengt h > 0)
{
e.Cancel = true;
MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
MessageBoxIcon. Exclamation);
}
<da*@msdn.com > 写入消息新闻:Op **************@ TK2MSFTNGP10.ph x.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.Lengt h > 0)
{
MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
MessageBoxIcon. Exclamation);
e.Cancel = true;
}

Can you help me ?

Thank you !



Nov 17 '05 #7
Thank you !

My mistake. I manage the enter key in KeyPress event and I doubled this key
by mistake.

Dan

"YUN SHI" <te*******@hotm ail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
See this

private void txtCode_Validat ing(object sender,
System.Componen tModel.CancelEv entArgs e)
{
if (txtCode.Text.L ength > 5)
{
e.Cancel = true;
MessageBox.Show ("The Code should not be more than 5 chars!", "Warning
!", MessageBoxButto ns.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******** ******@TK2MSFTN GP14.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.Lengt h > 0)
> {
> e.Cancel = true;
> MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
> MessageBoxIcon. Exclamation);
> }
>
>
> <da*@msdn.com > 写入消息新闻:Op **************@ TK2MSFTNGP10.ph x.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.Lengt h > 0)
>> {
>> MessageBox.Show (txtMSG, "Warning !", MessageBoxButto ns.OK,
>> MessageBoxIcon. Exclamation);
>> e.Cancel = true;
>> }
>>
>> Can you help me ?
>>
>> Thank you !
>>
>>
>
>



Nov 17 '05 #8

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

Similar topics

0
476
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 twice (event fired twice). Without event is fired once. if(txtMSG.Length > 0) {
11
7766
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 the web server performs a database query and displays the results. All of this works fine. I want the user to be able to press the Enter key while the cursor is still in SearchTextBox and have the SearchButton.Click event fire (thus performing...
0
1557
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 control which had it's causes validation property set to true however if I tabbed on to this control the event wouldn't fire. So after playing around with my code I figured out how to get it to work. I am not sure what the reason behind it is but it...
8
3490
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 offers a Cancel. Not on a textbox.
10
3136
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 the Button then Click on the TextBox and enter an "a" then click on the Button again. The following is what I get for the event tracking Arraylist: but - GotFocus but - Clicked but - LostFocus txt - Changed
6
3316
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" objCol.Width = 60 objCol.Format = "C" objDGTS.GridColumnStyles.Add(objCol) ' create keypress, validating events for this textbox column only Dim dgtb As DataGridTextBox = CType(objCol.TextBox, DataGridTextBox)
5
4700
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 control
14
14645
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 presses the "Save" button while the textbox has the focus, the LostFocus code doesn't run at the right time, so that the "Save" function is dealing with an incorrectly formatted string and the whole caboodle goes splat.
3
1978
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 custom message form) if he wants to see his old entry in a new form. if he/she choose Yes, I create a new form and show the previously entered data in it. The problem is when I create and show the new form, the validating event is fired two...
0
9851
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we抣l explore What is ONU, What Is Router, ONU & Router抯 main usage, and What is the difference between ONU and Router. Let抯 take a closer look ! Part I. Meaning of...
0
9694
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10901
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10583
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10286
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7824
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7012
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4481
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3128
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.