473,379 Members | 1,312 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,379 software developers and data experts.

Big time problem with VB.NET validation

Source code attached indicates my problem with validation and a button
bar save button.

Fill the Textbox with some text then tab off the control. The message
box will display the text in the textbox from the Validating event.
Now put the focus back on the textbox click the button bar button.
Nothing happens.

The form causes validation is true, so is the button bar and the
control.

This is a big issue for me as some validation code is in the control
and some is in a save validation event.

How do I validate a control that still has the focus to stop my save
validation event?

If I set the focus to some other control the textbox validating event
will fire but it will not stop the save validation.

I certainly do not want to have to code my controls and then put that
same code in my save validation event. Thirty controls on a form will
change your mind about that real fast.

If I attempt to fire a controls Validating event from the save
validation event I do not get a return value so I do not know if the
Validating event succeeded or not.

There has to be a better way! Does anyone out there have any
suggestions?

Public Class Form2
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents ToolBarButton1 As
System.Windows.Forms.ToolBarButton
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.ToolBar1 = New System.Windows.Forms.ToolBar
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton
Me.SuspendLayout()
'
'ToolBar1
'
Me.ToolBar1.Buttons.AddRange(New
System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1})
Me.ToolBar1.DropDownArrows = True
Me.ToolBar1.Location = New System.Drawing.Point(0, 0)
Me.ToolBar1.Name = "ToolBar1"
Me.ToolBar1.ShowToolTips = True
Me.ToolBar1.Size = New System.Drawing.Size(292, 28)
Me.ToolBar1.TabIndex = 0
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(48, 136)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(206, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(60, 202)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(184, 40)
Me.Button1.TabIndex = 2
Me.Button1.Text = "Save"
'
'ToolBarButton1
'
Me.ToolBarButton1.ToolTipText = "Save"
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.ToolBar1)
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If TextBox1.Text <> "" Then
MsgBox("TextBox1.Text = " & TextBox1.Text)
End If
End Sub
End Class
Nov 20 '05 #1
2 6680
Hello Tim

Despite Microsoft's attempts to improve control validation through the use
of control focus or validation events, it still is buggy and unpredictable
under certain circumstances. A better approach to form validation (IMHO) is
to use a state-machine approach that is driven independantly from control
events. I am assuming that you want to allow CRUD operations based on the
validity of the form's displayed data. By using a state-machine approach
you can control user options based on data validity regardless of where they
click and in what sequence they click.

Ibrahim
"Tim Frawley" <ti*********@fishgame.state.ak.us> wrote in message
news:bf*************************@posting.google.co m...
Source code attached indicates my problem with validation and a button
bar save button.

Fill the Textbox with some text then tab off the control. The message
box will display the text in the textbox from the Validating event.
Now put the focus back on the textbox click the button bar button.
Nothing happens.

The form causes validation is true, so is the button bar and the
control.

This is a big issue for me as some validation code is in the control
and some is in a save validation event.

How do I validate a control that still has the focus to stop my save
validation event?

If I set the focus to some other control the textbox validating event
will fire but it will not stop the save validation.

I certainly do not want to have to code my controls and then put that
same code in my save validation event. Thirty controls on a form will
change your mind about that real fast.

If I attempt to fire a controls Validating event from the save
validation event I do not get a return value so I do not know if the
Validating event succeeded or not.

There has to be a better way! Does anyone out there have any
suggestions?

Public Class Form2
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents ToolBarButton1 As
System.Windows.Forms.ToolBarButton
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.ToolBar1 = New System.Windows.Forms.ToolBar
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton
Me.SuspendLayout()
'
'ToolBar1
'
Me.ToolBar1.Buttons.AddRange(New
System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1})
Me.ToolBar1.DropDownArrows = True
Me.ToolBar1.Location = New System.Drawing.Point(0, 0)
Me.ToolBar1.Name = "ToolBar1"
Me.ToolBar1.ShowToolTips = True
Me.ToolBar1.Size = New System.Drawing.Size(292, 28)
Me.ToolBar1.TabIndex = 0
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(48, 136)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(206, 20)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(60, 202)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(184, 40)
Me.Button1.TabIndex = 2
Me.Button1.Text = "Save"
'
'ToolBarButton1
'
Me.ToolBarButton1.ToolTipText = "Save"
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.ToolBar1)
Me.Name = "Form2"
Me.Text = "Form2"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If TextBox1.Text <> "" Then
MsgBox("TextBox1.Text = " & TextBox1.Text)
End If
End Sub
End Class

Nov 20 '05 #2
Hi Tim,

Thanks for you posting in this group!
How do I validate a control that still has the focus to stop my save
validation event?


As for TextBox control, I think you could put your validation code into
the "Key_Press" event(instead of validate event) to trap the "Return" key
press, it is usual to do a validation check while user press the Return key
in the TextBox, and you also can stop your save validation via setting a
form-scope flag variant(then evaluate it to determine whether or not to
skip the validation routine while the save event is being invoked, and
reset the flag variant before the event function returns).
Best Regards!

Gary Chang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "AS IS" with no warranties,and confers no rights.
--------------------

Nov 20 '05 #3

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

Similar topics

2
by: Megha Vishwanath | last post by:
Hi, We have an application where my clients may be at different timezones. I need to validate time across the timezones with javascript. The date object in JavaScript does not allow me to get...
6
by: Kenneth | last post by:
Hello, I'm having some serious problems debugging a script that I'm trying to make work. I'm working on a form where a user can type in a time (in the format of HH:MM), and another script...
3
by: LDD | last post by:
Are there any built in time and/or date validation methods that one can make use of in .NET? thanks folks LDD
8
by: Marc | last post by:
Hi! I'm calling a web service using C# and a wrapper class generated by wsdl tool. The web service specification contains some nillable parameters which types are Value Types in .NET (long, int,...
9
by: ThunderMusic | last post by:
Hi, I'd like to create a compile time error in my class... maybe there's a way already built in in the framework so I can achieve what I want... I have 2 constructors in my class. One of them...
23
by: mosesdinakaran | last post by:
Hi All, I need a small clarification in submitting the forms, Ur suggestions please. In a page I have two form and also two submit butons. (ie)
6
by: Steve Ryan | last post by:
can anyone send me to some good examples of edit in place for data frid columns i see dot net let me assign a control in the IDE any good sources of reading on editing columns with controls...
6
by: tatata9999 | last post by:
Hi all, I have this simple time management tool designed and developed. And based on a very thoughtful and kind Frenchman's input I've extended its support to international (support all time...
1
by: asayer | last post by:
Hello, First I want to say I am not really a db person, just a biologist with a database. There is a subform within one of my forms where various users enter a series of a few dozen events, each of...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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 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.