ErrorProvider CodeSample - Errorchecking whole form on a button click
From Visual WebGui Wiki
| This article will have a few sections added to it soon, based on the following article type skeleton: NewCodeSampleTemplate |
Overview
This is just a very simple sample on how to use the control. Attaching the error checking to the validation of each textbox control is what is usually prefered as opposed to this case which provides a Button to error check the whole form at the same time. Attaching those error checking to the validation events gives the user more feeling of "online" error checking.
VB.NET Code
Imports Gizmox.WebGui.Forms Public Class Form1 Friend WithEvents TextBox1 As Gizmox.WebGui.Forms.TextBox Friend WithEvents EP As Gizmox.WebGui.Forms.ErrorProvider Friend WithEvents TextBox2 As Gizmox.WebGui.Forms.TextBox Friend WithEvents btnSaveButton As Gizmox.WebGui.Forms.Button Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.TextBox1 = New Gizmox.WebGui.Forms.TextBox Me.EP = New Gizmox.WebGui.Forms.ErrorProvider(Me.components) Me.TextBox2 = New Gizmox.WebGui.Forms.TextBox Me.btnSaveButton = New Gizmox.WebGui.Forms.Button Me.TextBox1.Location = New System.Drawing.Point(12, 27) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(100, 20) Me.TextBox1.TabIndex = 0 Me.EP.BlinkRate = 3 Me.EP.BlinkStyle = Gizmox.WebGui.Forms.ErrorBlinkStyle.BlinkIfDifferentError Me.EP.DataMember = "" Me.EP.DataSource = "" Me.EP.Icon = Nothing Me.TextBox2.Location = New System.Drawing.Point(151, 27) Me.TextBox2.Name = "TextBox2" Me.TextBox2.Size = New System.Drawing.Size(100, 20) Me.TextBox2.TabIndex = 1 Me.btnSaveButton.Location = New System.Drawing.Point(273, 24) Me.btnSaveButton.Name = "btnSaveButton" Me.btnSaveButton.Size = New System.Drawing.Size(75, 23) Me.btnSaveButton.TabIndex = 2 Me.btnSaveButton.Text = "Save" AddHandler btnSaveButton.Click, AddressOf btnSaveButton_Click Me.Controls.Add(Me.btnSaveButton) Me.Controls.Add(Me.TextBox2) Me.Controls.Add(Me.TextBox1) End Sub Private Sub btnSaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If AreWeErrorFree() Then MessageBox.Show("We are error free!") Else MessageBox.Show("We have some errors!") End If End Sub Private Function AreWeErrorFree() As Boolean EP.SetError(TextBox1, "") EP.SetError(TextBox2, "") If TextBox1.Text = "" Then EP.SetError(TextBox1, "You must enter text") End If If TextBox2.Text = "" Then EP.SetError(TextBox2, "You must enter text") End If Return EP.GetError(TextBox1) = "" And EP.GetError(TextBox2) = "" End Function End Class
C# Code
| The conversion of this code to C# has not been completed yet. Please feel free to contribute and add contents to the Wiki |
