954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problem passing dialog result

I have a function for a dialog which returns the dialog result back.
However, the value of the dialogresult changes from ok to cancel after the value is returned. How can i fix this?

this is the part where the dialog is called and the value from the dialog is returned.

Private Sub btnLogin_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnLogin.ItemClick
        Dim loginDialog As New frmLogin
        Dim result As DialogResult = Nothing
        result = loginDialog.ShowDialog()
        If result = Windows.Forms.DialogResult.OK Then
            If My.Settings.User = "administrator" Then My.Settings.AccessCode = "admin"
            My.Settings.AccessCode = ShippingClass.funcGetAcessCode(My.Settings.User)
            Log_On()
        End If
          End Sub


This is the function that returns the dialog result.

Private Function OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim result As DialogResult

        If txtPassword.Text = Nothing Or txtUserID.Text = Nothing Then
            MessageBox.Show("Please check your user name and password", "Invalid Login")
            Exit Function
        End If

        If ShippingClass.funcAuthenticate(txtUserID.Text, txtPassword.Text) = True Then
            My.Settings.User = txtUserID.Text
            doExit = True
            Me.Close()
            result = Windows.Forms.DialogResult.OK
            Return result
        Else
            MessageBox.Show("Authentication Failed:" & vbCrLf & "The User ID and password you have entered does not match. Please check your login info and try again.", "Authentication Failure")
        End If
    End Function


****
btnLogin_ItemClick opens login dialog which returns a value as result back to btnLogin_ItemClick using the function OK_Click.
While debugging, the returning value after sucessful authentication should and is dialogresult.ok until it is passed back to btnLogin where the result value changes from 'Ok' to 'Cancel'

bluehangook629
Posting Whiz in Training
204 posts since Dec 2009
Reputation Points: 11
Solved Threads: 14
 


Looks like me.close may be giving you a problem.

I would change:

If ShippingClass...... then
    My.Settings.User = txtUserID.Text
    Me.DialogResult = Windows.Forms.DialogResult.OK
else
  ...
End if


And your Private Function OK_Click should be Private Sub OK_Click . When handling an event it doesn't return a value.

Unhnd_Exception
Posting Pro
571 posts since Nov 2010
Reputation Points: 249
Solved Threads: 201
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: