ASP.NET 1.0 and 1.1 BasicsASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
How can i call a method to validate atext box in windows forms?
I have currently written as
this.txtmno.LostFocus=Validate(txtmno.Text);
but its displaying error as the event "System.Windows.Form.Control.LostFocus should be on leftside of the =+-.
what may be possible solution to this.
18. Validating the data entered in the Amount TextBox control.
This event occurs when the input focus leaves the control. This event procedure is to check for whether data entered in amount text box control is valid.
Private Sub mAmount_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles mAmount.LostFocus
If Not IsNumeric(mAmount.Text) And mAmount.Text <> " " Then
MsgBox("Not a Numeric Input! Try again.")
mAmount.Focus()
Exit Sub
ElseIf (mAmount.Text < 0) Then
MessageBox.Show("Enter positive Amount")
mAmount.Focus()
Exit Sub
End If
End Sub
The TextChanged event occurs when the content in the TextBox control is changed. Select mAmount in LHS combobox and TextChanged in the RHS combobox to program this event. We use IsNumeric() function to check the value entered in the amount text box control is numeric data. We also check whether the value entered in this text box is empty. If any of these conditions are true, then we will display a message box and set the focus to the Amount text box control.
Private Sub mAmount_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles mAmount.TextChanged
If Not IsNumeric(mAmount.Text) And mAmount.Text <> " " Then
MsgBox("Not a Numeric Input! Try again.")
mAmount.Focus()
Exit Sub
End If
End Sub