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 ! 7 7746
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 !
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 !
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 !
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 !
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 !
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 !
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 ! >> >> > >
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 twice (event fired twice).
Without event is fired once.
if(txtMSG.Length > 0)
{
|
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...
|
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...
|
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.
|
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...
| |
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...
|
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
|
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...
|
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...
|
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...
|
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. ...
| |
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |