T
tshad
How do I get my Custom Validator to work? All the other validators work
fine.
Here is the Textbox and Validator:
***********************************************
<asp:textbox id="email" TextMode="SingleLine" Columns="32"
runat="server" />
<asp:RegularExpressionValidator ControlToValidate="email" Text =
"Invalid Email Address!"
ValidationExpression="\S+@\S+\.\S{2,3}" runat="server" />
<asp:RequiredFieldValidator
ControlToValidate="email"
Text="You must enter an email"
runat="server" />
<asp:CustomValidator
ControlToValidate="email"
OnServerVAlidate="ValidateEmail"
Display="Dynamic"
Text="Email already on File"
runat="server" />
*********************************************************************
Here is the ValidateEmail code:
*****************************************************************
Sub ValidateEmail(s as Object,e as ServerValidateEventArgs)
trace.warn("in ValidateEmail")
Dim sResults As String
Dim emailReader As SqlDataReader
Dim ConnectionString as String
=System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_ftsolutions")
Dim objConn as New SqlConnection (ConnectionString)
Dim CommandText as String = "Select email from logon where email = @Email"
Dim objCmd as New SqlCommand(CommandText,objConn)
with objCmd.Parameters
.Add("@Email",SqlDbType.VarChar,45).value = email.text
end with
objConn.Open()
emailReader = objCmd.ExecuteReader
trace.warn("before emailReader.Read")
if emailReader.Read then
trace.warn("not valid")
e.IsValid = false
end If
End Sub
*****************************************************************
I do get to the "not valid trace line".
But it also goes to the insertRecord routine (which is hooked to the
button).
How do I tell it - If there is an email record - don't do the insertRecord
routine:
*******************************************************************
Sub InsertRecord()
trace.warn("inside insertRecord")
Dim sResults As String
Dim ConnectionString as String
=System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_ftsolutions")
Dim objConn as New SqlConnection (ConnectionString)
Dim CommandText as String = "INSERT INTO ftsolutions.dbo.logon
(FirstName,LastName,Email,Password) VALUES
(@FirstName,@LastName,@Email,@Password)"
Dim objCmd as New SqlCommand(CommandText,objConn)
with objcmd.Parameters
.Add("@FirstName",SqlDbType.VarChar,15).value = firstName.text
.Add("@LastName",SqlDbType.VarChar,30).value = lastName.text
.Add("@Email",SqlDbType.VarChar,45).value = email.text
.Add("@Password",SqlDbType.VarChar,20).value = password.text
end with
objConn.Open()
objCmd.ExecuteNonQuery
End Sub
*************************************************************
I set e.IsValid to false - so how do I tell insertRecord to look at it?
Thanks,
Tom.
fine.
Here is the Textbox and Validator:
***********************************************
<asp:textbox id="email" TextMode="SingleLine" Columns="32"
runat="server" />
<asp:RegularExpressionValidator ControlToValidate="email" Text =
"Invalid Email Address!"
ValidationExpression="\S+@\S+\.\S{2,3}" runat="server" />
<asp:RequiredFieldValidator
ControlToValidate="email"
Text="You must enter an email"
runat="server" />
<asp:CustomValidator
ControlToValidate="email"
OnServerVAlidate="ValidateEmail"
Display="Dynamic"
Text="Email already on File"
runat="server" />
*********************************************************************
Here is the ValidateEmail code:
*****************************************************************
Sub ValidateEmail(s as Object,e as ServerValidateEventArgs)
trace.warn("in ValidateEmail")
Dim sResults As String
Dim emailReader As SqlDataReader
Dim ConnectionString as String
=System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_ftsolutions")
Dim objConn as New SqlConnection (ConnectionString)
Dim CommandText as String = "Select email from logon where email = @Email"
Dim objCmd as New SqlCommand(CommandText,objConn)
with objCmd.Parameters
.Add("@Email",SqlDbType.VarChar,45).value = email.text
end with
objConn.Open()
emailReader = objCmd.ExecuteReader
trace.warn("before emailReader.Read")
if emailReader.Read then
trace.warn("not valid")
e.IsValid = false
end If
End Sub
*****************************************************************
I do get to the "not valid trace line".
But it also goes to the insertRecord routine (which is hooked to the
button).
How do I tell it - If there is an email record - don't do the insertRecord
routine:
*******************************************************************
Sub InsertRecord()
trace.warn("inside insertRecord")
Dim sResults As String
Dim ConnectionString as String
=System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_ftsolutions")
Dim objConn as New SqlConnection (ConnectionString)
Dim CommandText as String = "INSERT INTO ftsolutions.dbo.logon
(FirstName,LastName,Email,Password) VALUES
(@FirstName,@LastName,@Email,@Password)"
Dim objCmd as New SqlCommand(CommandText,objConn)
with objcmd.Parameters
.Add("@FirstName",SqlDbType.VarChar,15).value = firstName.text
.Add("@LastName",SqlDbType.VarChar,30).value = lastName.text
.Add("@Email",SqlDbType.VarChar,45).value = email.text
.Add("@Password",SqlDbType.VarChar,20).value = password.text
end with
objConn.Open()
objCmd.ExecuteNonQuery
End Sub
*************************************************************
I set e.IsValid to false - so how do I tell insertRecord to look at it?
Thanks,
Tom.