Very new to asp.net and would like an explanation of how the following works.
Maybe this is just how .net works but I don't like it :)
I have a one field form that uses a validation control (required field validator) and it works I can not submit the form until something is typed in...cool right!
From what is taken in on my sub_pageLoad function I check for isPostback and then call a sql statement to validate what was typed in the box against what exists in the db (please disregard the possibility for sql injection) this is just for testing with .net
In anycase if the field does not match I am displaying another error in a label that says sorry your credentials are not valid..etc I tried to just assign the text property of the error control and enabled it but that didnt work?
So up to now it works just how I would expect...but here is the issue I have....so if I get past the validator control and then enter an incorrect value in the field...then for some reason I clear out the input and try to login again I get both error messages...and that is the whole point of this posting Why???? How can I tell asp.net that the page should always try and validate itself...not just once.
Code provided below
Thanks
Code:
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack Then
'Make sure no validator errors
Page.Validate()
If Page.IsValid Then
'Start by determining the connection string value
Dim connString As String = _
ConfigurationManager.ConnectionStrings("clientsTestConnectionString").ConnectionString
'Create a SqlConnection instance
Using myConnection As New SqlConnection(connString)
'Specify the SQL query
Dim emailToVerify As String = txtEmail.Text
Dim sql As String = "SELECT id_client FROM clients where client_email='" & Request("txtEmail") & "'"
'Create a SqlCommand instance
Dim myCommand As New SqlCommand(sql, myConnection)
'Get back a DataSet
Dim myDataSet As New DataSet
'Open connection
myConnection.Open()
' Set an OleDbDataReader to the command's results
Dim objDataReader As SqlDataReader
objDataReader = myCommand.ExecuteReader()
If (objDataReader.HasRows) Then
objDataReader.Read()
Session("id_client") = objDataReader("id_client")
Else 'email address not found in db
lblLoginError.Text = "Your email address was not found in the system"
End If
myConnection.Close()
End Using
End If ' end valid
End If ' end postback
End Sub
End Class
http://mynameissteve.com