Results 1 to 12 of 12

Thread: [RESOLVED] CausesValidation=false not working?

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    101

    Re: CausesValidation=false not working?

    tg: ok check this out!

    VB Code:
    1. Public Class Form1
    2.  
    3.  
    4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         Button1.CausesValidation = False
    6.     End Sub
    7.  
    8.  
    9.     Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
    10.         If TextBox1.Text = "" Then
    11.             MsgBox("You must enter something")
    12.             e.Cancel = True
    13.         End If
    14.     End Sub
    15.  
    16.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    17.         MsgBox("Button1Click - No Me.Close event")
    18.         'MsgBox "Button1Click - Yes Me.Close event"
    19.         'Me.Close
    20.     End Sub
    21. End Class

    this is just a simple 1 form, 1 button, 2 textbox form. Please test this program and you'll see some weird (might be working right, who am i to say) stuff.

    Notice that if you enable the code in button1 click, namely Me.Close, then the validation event for textbox1 will fire. But if you leave it disabled then you can get the MsgBox("Button1Click - No Me.Close event") just fine, however try and go straight to the close form "x" and then the textbox1 validating event fires. So, it's like it's still sitting at the TextBox1 validating event, but it allows non event things to happen?

    EDIT: I'm beginning to think that I might be trying to use the CausesValidation event for something it's not meant to do. I mean, it makes sense to me that it would work how I want it to; that way if the user enters information that I cannot accept I can allow them the ability to cancel out of the form. That being said, it seems like the msdn pages are refering to using CausesValidation to pop up some Help for the user.
    Last edited by Essential; Mar 7th, 2006 at 07:25 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width