Lost Focus problems - vb.net

I use the LostFocus Event in vb.net to check the validity of a field for the name.
After this field a have another one which is the for the password validity, and i'm handilg the same event in order to check the password.
My problem comes when i run the (name) lost focus, runs the code inside the sub and after that automatically goes to the password_lostfocus which brings me alot of troubles.
That happens even i use the error provider which works fine and bring to me the error with the red flashing.After that i put the command (name_textbox.focus), which logically has to bring the control in the name_textbox.. But NO.. the control goes to the Password_textbox sub automatically.
Please see my sub
Private Sub UsernameTextBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles UsernameTextBox.LostFocus
Select Case DB_Access.IfExistUser(UsernameTextBox.Text, sender, e)
Case True
PasswordTextBox.Focus()
Case False
ErrorProvider1.SetError(UsernameTextBox, "Ο χρήστης ΔΕΝ υπάρχει παρακαλώ καλέστε τον Administrator")
Beep()
UsernameTextBox.Text = ""
UsernameTextBox.Focus()
End Select
End Sub
Please if anyone have seen this issue and face it, assist me.
Excuse me for some Greek characters they are meaningless, they are comments

Well finally i found that.
In order to handle the Login Form as it give it from visual studio 2010 you need to do it in only one sub (Lost Focus) and that is only the password_LostFocus.
I believe the particular form is meant to be like that.
Any way i solve the issue and if anybody needs assistance on that just "asc a question"

Related

VB.Net - Manage errors label

I'm working on visual studio 2015 and I'm working on a classic subscribing form.
I want to generate error labels when the user type wrong password, the wrong pseudo, etc. But I can work on it myself.
But when I write those error labels and set their visible at false in "Dev mode", I have to juxtapose those labels if I want my labels at the same place, and it's not what I want when I have many errors to manage on one textBox for example.
Is there a solution to gererate those labels, without write them before playing with hide() or show() ?
Here is the screenshot in order to illustrate my problem.
It's not really a problem itself, but It's not practical when I'm develop many errors.
Sorry for my english, I hope you understood my problem, I can give you more details =)
Have a nice day full of code !
Here the button code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> "Password" Then
Label2.Text = "Your answer is wrong"
End If
End Sub
This is what it looks like:

Referring To MessageBox VB.NET

I'm writing a program that kids can use to code from within my application instead of a console-based approach
So I have a lesson that teaches them about message boxes, they are given a sample line of code and what it creates and are told to create their own by entering code into a textbox to create their own that says "Hey Dude!", the problem is, I'm having trouble getting the system to check if what they entered was correct or not... eg:
Private Sub btnShowMsgBox_Click(sender As Object, e As EventArgs) Handles btnShowMsgBox.Click
If txtUserInput.Text = MessageBox.Show("I can code!") Then
MessageBox.Show("I can code!")
Else
MessageBox.Show("That's not quite right, try again!")
End If
I've tried adding " " around the relevent code on the first line of the if statement but no joy, as well as trying a variable approach
So basically the problem is the program is getting confused and doesn't understand why I'm checking to see if code for a message box is present, the syntax of the messagebox code doesn't fit well either
Does anyone have any suggestions as to how I would get this working? The logic is so straightforward but it's driving me nuts!
Thanks a million in advance
I believe you want the code to look more like...
Private Sub btnShowMsgBox_Click(sender As Object, e As EventArgs) Handles btnShowMsgBox.Click
If txtUserInput.Text = "MessageBox.Show(""I can code!"")" Then
MessageBox.Show("I can code!")
Else
MessageBox.Show("That's not quite right, try again!")
End If
The double quotes will return as single quotes within the string between the single quotes.

Winforms RadTextBox control validating event triggered twice

I am doing a database validation on the TextBox validating event. I am also using the e.Cancel = True if the data is invalid. The problem is that the validating event is triggered twice ultimately causing the SQL also to run twice, and I don't want that to happen (coz sometime the query is resource intensive).
Steps:
Drag & drop a RadTextBox & a RadLabel to the Form.
For the RadTextBox validating event use the below code.
Run the application, focus the RadTextBox & then click on the label. Then if you check the output window of visual studio you will notice that the console has logged that the validating event was actually triggered twice. (The event runs twice only when I try to click a RadButton or a RadLabel)
I noticed this bug when I was checking my queries in SQL Server Profiler & the query gets executed twice, which is unnecessary. I also checked with actual wincontrols & this issue doesn't exist in them.
How do I fix this issue ?
Here a sample code to replicate the behavior
Private Sub RadTextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles RadTextBox1.Validating
Console.WriteLine("VALIDATING EVENT TRIGGERED")
e.Cancel = True
End Sub
It seems as a known issue with RadTextBox: issue link
Perhaps you can try RadTextBoxControl for your needs?

Weird functionality when using ScriptManager.RegisterStartupScript

I'm having this weird problem using the ScriptManager.RegisterStartupScript. Basically what I'm trying to accomplish when I click a button control, it goes back to the server, checks to see if any errors, and what I want to happen is that if there are any errors, want to use a popup box. The button control is inside an update panel. I thought the easiest way to accomplish this was to use a javascript alert box. So I finally got it working but when the alert box comes up it messes up my menu control until the alert box is going then its ok. Its kinda of hard to explain so I have insert a image to show you guys whats going on once the button is clicked. I dont know how to fix or whats going on, if someone could point me into the right direction. Also he my code im using.
Protected Sub btnPlan_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnPlan.Click
'Dim sb As New System.Text.StringBuilder
sb.Append("<script language='javascript'>")
sb.Append("alert(' No data in the database ');")
sb.Append("</script>")
If (Not ClientScript.IsStartupScriptRegistered("JSScript")) Then
ScriptManager.RegisterStartupScript(UpdatePanel5, Me.GetType(), "JSScript", sb.toString(), True)
End If
You may try to use RegisterClientScriptBlock:
Protected Overrides Sub Page_Load(ByVal sender as Object, ByVal e As System.EventArgs)
MyBase.Page_Load(sender, e)
Try
If Not ScriptManager.IsInAsyncPostBack Then
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "AlertScript", "<script type='text/javascript' language='javascript'>function YourAlert(){alert(' No data in the database ');}</script>")
EndIf
Catch ex As Exception
End Try
End Sub
Thanks for all your suggestion. I skinned this a different way and got it to work the way I wanted. What i did was put the message in a hidden textbox and used jquery to ensure that the page was already load then alert the message if needed.

Printing Active Child Form

I am new to VB and today I programmed my first form that uses parent and child forms. The assignment asks to "print the active child form" and I am a little stuck. So far this semester printing has not really been a big part of the assignments and I can't seem to find much in the book.
The way the assignment is coded is in the parent form there is a menu strip and I created a print click event in the menu. I guess I'm unsure where to start to make this be able to print just the active child form. My extent of printing my forms has been been dropping a printform from the VB powerpacks and then coding the form to print to preview.
Can someone point me in the right direction? Any hint would be huge so I know at least what to look for in the book. This is for homework.
I found the answer to my own question. Here is a snipped of the code I used. I ended up keeping my printform from the powerpack I just was hung up on how to tell the program to find the active form.
Here is the code I used.
Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click, PrintToolStripButton.Click
If Me.ActiveMdiChild Is Nothing Then
Return
End If
PrintForm1.Form = Me.ActiveMdiChild
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
End Sub