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.AppSet tings("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.AppSet tings("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. 4 3665
Tshad,
I noticed one thing in your code: you specified a ControlToValidate in
your custom validater. This property should be left off.
Best regards,
Jeffrey Palermo
"tshad" <ts**********@ftsolutions.com> wrote in message
news:ed**************@TK2MSFTNGP15.phx.gbl... 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.AppSet tings("MM_CONNECTION_STRIN
G_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.AppSet tings("MM_CONNECTION_STRIN
G_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.
Guess u are missing something :-
Go to :- http://samples.gotdotnet.com/quickstart/aspplus/
and read :- Server Control Form Validation
Enjoy
"tshad" wrote: 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.AppSet tings("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.AppSet tings("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.
"Jeffrey Palermo [MCP]" <http://dotnetjunkies.com/weblog/jpalermo> wrote in
message news:%2****************@TK2MSFTNGP15.phx.gbl... Tshad, I noticed one thing in your code: you specified a ControlToValidate in your custom validater. This property should be left off.
That didn't work.
The same thing happens. With trace on, I can see it going to the validation
function, but it also does the insert, which is where the button sends it.
Also, the books I have show that the ControlToValidate are supposed to be
there for the custom validator. Are there instances where you want it and
others where you don't?
Thanks,
Tom. Best regards, Jeffrey Palermo
"tshad" <ts**********@ftsolutions.com> wrote in message news:ed**************@TK2MSFTNGP15.phx.gbl... 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.AppSet tings("MM_CONNECTION_STRIN G_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.AppSet tings("MM_CONNECTION_STRIN G_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.
"Patrick.O.Ige" <Pa*********@discussions.microsoft.com> wrote in message
news:DA**********************************@microsof t.com... Guess u are missing something :- Go to :- http://samples.gotdotnet.com/quickstart/aspplus/ and read :- Server Control Form Validation Enjoy
Found it there.
I didn't see the "IsValid" in the buttons routine.
What I had to do was add to the ModifyRecord_click routine:
*************************************************
Sub ModifyRecord_click(sender as Object, e as EventArgs)
if Not Page.IsValid then
exit sub
end if
************************************************** *
and it works fine.
Thanks,
Tom
"tshad" wrote:
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.AppSet tings("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.AppSet tings("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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jcpmeticulus |
last post by:
Hi
I've spent the last day or so debugging a problem with a CustomValidator and
am now totally stumped! Basically I use a number of CustomValidator's on my
page, but have cut this down now to...
|
by: Stephen Miller |
last post by:
Can the CustomValidator be used to simply report unexpected errors,
without requiring Client/Server validation? To explain, say you had a
simple text box and button that did a Full-text Search of a...
|
by: Ronan Dodworth |
last post by:
Hi there
I'm having a little bit of a problem with my customvalidator control.
The problem is the javascript runs fine on my local webserver IIS but
not when I post it to the web hosting server....
|
by: SMG |
last post by:
Hi All.
My forms has two textboxes, 1 username, 2 password.
Both has requiredfield validator it works fine when there is no input in
these textboxes.
And the errorMsg is shown in...
|
by: ghafranabbas |
last post by:
This is how you use the customvalidator control in any INamingContainer
interface control (Datagrid, DataList, DataRepeater, etc).
1. In the ItemTemplate, place your customvalidator
2. Set the...
|
by: Beffmans |
last post by:
Hi
I have defined an customvalidator on my TextBox:
function clientvalidate(source, arguments){
{
// even number?
if (arguments.Value%2 == 0)
arguments.IsValid = true;
else
|
by: cemcat |
last post by:
Hello,
We have an ASP.NET 2.0 (C#) web form that contains a textbox for users to
enter multiple e-mail addresses separated by semicolons. We need to
validate that each individual e-mail address...
|
by: David |
last post by:
I need help with CustomValidator in 1.1. I added the CustomValidator
control and code as per the doc., (See below) However, the code is
never executed. Is there an extra switch or setting to...
|
by: theresa |
last post by:
I'm about at my wits end trying to figure out why this isn't working,
so I'm hoping one of you can help! I'm sure there must be something
simple I'm missing.
I have a checkbox on an Asp.NET 2.0...
|
by: pompeymike |
last post by:
Hi, I have a form with panels, within which is a Formview. In the InsertItemTemplate for the FormView I have validation using RequireFieldValidators. These all work correctly, but if I use a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |