473,385 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

custom validation

I cant seem to get my custom validation to work. can anyone spot where i
have gone wrong

control
<asp:CustomValidator ID="checkHandicap" runat="server"
ControlToValidate="startHandicap" ErrorMessage="Handicap out of range"
OnServerValidate="checkHandicap_ServerValidate" ></asp:CustomValidator>

code behind
Protected Sub checkHandicap_ServerValidate(ByVal source As Object, ByVal
args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
checkHandicap.ServerValidate

Dim ans As Integer = Integer.Parse(args.Value)

Try

If ans -27 And ans <= 27 Then

args.IsValid = True

Exit Sub

End If

Catch exc As Exception

End Try

args.IsValid = False

End Sub


Aug 18 '06 #1
14 2592
Slim,

Are you getting an error message? What values are failing? I mocked up
an example using your code, but don't know how it's failing for you so
I don't really know how to help.

dkb

Aug 18 '06 #2
I get no error, but I get no return either,

from what tests I could do, the function was not firing

"Dblood" <db*********@infinitechs.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Slim,

Are you getting an error message? What values are failing? I mocked up
an example using your code, but don't know how it's failing for you so
I don't really know how to help.

dkb

Aug 18 '06 #3
Slim,

On the mockup I created, the event fired, and your code worked. I
don't see a reason why it would not work. I copied your control
declaration from the post, copied the code from the post. I dumped them
into a page, added the withevents declaration of the checkhandicap
variable, added a button (so that I could have the page postback) and
it worked.

There must be more to the problem. What is causing postback in your
app? Can you set a breakpoint, then run in debug and verify that the
checkHandicap_ServerValidate Sub is not being called? If not, add a
"response.write(args.IsValid)" at each of the conditions (where
args.IsValid is set to true or false) to ensure that the app is calling
the sub.

This is a weird one,

dkb

Aug 18 '06 #4

"Dblood" <db*********@infinitechs.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Slim,

On the mockup I created, the event fired, and your code worked. I
don't see a reason why it would not work. I copied your control
declaration from the post, copied the code from the post. I dumped them
into a page, added the withevents declaration of the checkhandicap
variable,
where do i put the with events?
added a button (so that I could have the page postback) and
it worked.

There must be more to the problem. What is causing postback in your
app? Can you set a breakpoint, then run in debug and verify that the
checkHandicap_ServerValidate Sub is not being called? If not, add a
"response.write(args.IsValid)" at each of the conditions (where
args.IsValid is set to true or false) to ensure that the app is calling
the sub.

This is a weird one,

dkb

Aug 18 '06 #5
What I mean is that when I copied your control (the text below) to an
aspx page, it didn't create the variable for me on the code-behind
page.

<asp:CustomValidator ID="checkHandicap" runat="server"
ControlToValidate="startHandicap" ErrorMessage="Handicap out of range"
OnServerValidate="checkHandicap_ServerValidate"></asp:CustomValidator>

So, I had to create that variable myself. Yours is probably already
there. Near the top of the code-behind view you'll see:

Protected WithEvents checkHandicap As CustomValidator

Any luck using the Response.write to see if the isvalid ever changes?
Can you debug the project and step through to see if the event is
firing?

dkb

Aug 18 '06 #6
No the response.write is not returning anything

and no where on my page or code behind is a WithEvents statement
"Dblood" <db*********@infinitechs.comwrote in message
news:11*********************@74g2000cwt.googlegrou ps.com...
What I mean is that when I copied your control (the text below) to an
aspx page, it didn't create the variable for me on the code-behind
page.

<asp:CustomValidator ID="checkHandicap" runat="server"
ControlToValidate="startHandicap" ErrorMessage="Handicap out of range"
OnServerValidate="checkHandicap_ServerValidate"></asp:CustomValidator>

So, I had to create that variable myself. Yours is probably already
there. Near the top of the code-behind view you'll see:

Protected WithEvents checkHandicap As CustomValidator

Any luck using the Response.write to see if the isvalid ever changes?
Can you debug the project and step through to see if the event is
firing?

dkb

Aug 19 '06 #7
Slim,

Add this to your code behind then,

Protected WithEvents checkHandicap As _
System.Web.UI.WebControls.CustomValidator
and then try again.

dkb

Aug 21 '06 #8

Dblood schrieb:
Slim,

Add this to your code behind then,

Protected WithEvents checkHandicap As _
System.Web.UI.WebControls.CustomValidator
and then try again.

dkb

Hey Slim. If I understand you right, I had the same problem some time
ago on the client side. In my case args.Value didn't return anything.
The event was fired, but arg.Value was empty.

My solution was to adress the textbox directly throug something like:
((TextBox)Page.FindControl("startHandicap")).Text

MfG
Georg Fleischer

Aug 22 '06 #9

"Dblood" <db*********@infinitechs.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Slim,

Add this to your code behind then,

Protected WithEvents checkHandicap As _
System.Web.UI.WebControls.CustomValidator
and then try again.
sorry took so long to reply

It tells me that it is already declared with events, yet its not on the
page.

I assume that VS2005 hides it from view.

dkb

Aug 24 '06 #10
I have since found that no events are working in the site except for page
load, they were working until recently?

"Slim" <me@here.comwrote in message
news:eT**************@TK2MSFTNGP04.phx.gbl...
>
"Dblood" <db*********@infinitechs.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
>Slim,

Add this to your code behind then,

Protected WithEvents checkHandicap As _
System.Web.UI.WebControls.CustomValidator
and then try again.

sorry took so long to reply

It tells me that it is already declared with events, yet its not on the
page.

I assume that VS2005 hides it from view.

>dkb


Aug 24 '06 #11
Hi Slim,

Try to add ValidateEmptyText="true" to your custom validator.
For more details read
http://msdn2.microsoft.com/en-us/lib...emptytext.aspx.

Regards,
Alex.

Slim wrote:
I cant seem to get my custom validation to work. can anyone spot where i
have gone wrong

control
<asp:CustomValidator ID="checkHandicap" runat="server"
ControlToValidate="startHandicap" ErrorMessage="Handicap out of range"
OnServerValidate="checkHandicap_ServerValidate" ></asp:CustomValidator>

code behind
Protected Sub checkHandicap_ServerValidate(ByVal source As Object, ByVal
args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
checkHandicap.ServerValidate

Dim ans As Integer = Integer.Parse(args.Value)

Try

If ans -27 And ans <= 27 Then

args.IsValid = True

Exit Sub

End If

Catch exc As Exception

End Try

args.IsValid = False

End Sub
Aug 24 '06 #12

"seigo" <se******@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Hi Slim,

Try to add ValidateEmptyText="true" to your custom validator.
thanks but no go
For more details read
http://msdn2.microsoft.com/en-us/lib...emptytext.aspx.

Regards,
Alex.

Slim wrote:
>I cant seem to get my custom validation to work. can anyone spot where i
have gone wrong

control
<asp:CustomValidator ID="checkHandicap" runat="server"
ControlToValidate="startHandicap" ErrorMessage="Handicap out of range"
OnServerValidate="checkHandicap_ServerValidate" ></asp:CustomValidator>

code behind
Protected Sub checkHandicap_ServerValidate(ByVal source As Object, ByVal
args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
checkHandicap.ServerValidate

Dim ans As Integer = Integer.Parse(args.Value)

Try

If ans -27 And ans <= 27 Then

args.IsValid = True

Exit Sub

End If

Catch exc As Exception

End Try

args.IsValid = False

End Sub

Aug 24 '06 #13

"Slim" <me@here.comwrote in message
news:OO**************@TK2MSFTNGP02.phx.gbl...
>I have since found that no events are working in the site except for page
load, they were working until recently?
sorry false alarm, its only that page, event a simple button on click event
will not work on the page.

I have recreated a new page with new code behind page, and when I copy html
and controls I have the same problems
>
"Slim" <me@here.comwrote in message
news:eT**************@TK2MSFTNGP04.phx.gbl...
>>
"Dblood" <db*********@infinitechs.comwrote in message
news:11**********************@p79g2000cwp.googleg roups.com...
>>Slim,

Add this to your code behind then,

Protected WithEvents checkHandicap As _
System.Web.UI.WebControls.CustomValidator
and then try again.

sorry took so long to reply

It tells me that it is already declared with events, yet its not on the
page.

I assume that VS2005 hides it from view.

>>dkb



Aug 24 '06 #14
Sorry to waste your time

I found that I had to make sure the all other required validation controls
were satisfied before custom validation would work.

after pulling my hair out for days, I calmed down took a deep breath and had
a logical look at my code,

thanks for your time

"Slim" <me@here.comwrote in message
news:ev**************@TK2MSFTNGP04.phx.gbl...
>
"Slim" <me@here.comwrote in message
news:OO**************@TK2MSFTNGP02.phx.gbl...
>>I have since found that no events are working in the site except for page
load, they were working until recently?

sorry false alarm, its only that page, event a simple button on click
event will not work on the page.

I have recreated a new page with new code behind page, and when I copy
html and controls I have the same problems
>>
"Slim" <me@here.comwrote in message
news:eT**************@TK2MSFTNGP04.phx.gbl...
>>>
"Dblood" <db*********@infinitechs.comwrote in message
news:11**********************@p79g2000cwp.google groups.com...
Slim,

Add this to your code behind then,

Protected WithEvents checkHandicap As _
System.Web.UI.WebControls.CustomValidator
and then try again.
sorry took so long to reply

It tells me that it is already declared with events, yet its not on the
page.

I assume that VS2005 hides it from view.
dkb



Aug 24 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Barbara Alderton | last post by:
I setup some standard Required Field Validation controls and one Custom validation control on an ASP.NET page (within a user control) to validate text entry. I also setup a Summary Control to post...
1
by: Stephen Adam | last post by:
Hi there, I have written a custom validation control which checks to see of an input field is not empty and contains only numeric data. I was using a regular expression validation control but...
5
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze...
9
by: wardy1975 | last post by:
Hi All, Looking for a little expert advice on a few web standards issues. I am currently trying to understand the impact of web standards for a web application I work with. I have been doing a...
0
by: Marek | last post by:
Hi all, I have custrom control with four elements: text box, regular expression validator, required field validator and custom validator. Next this control is dragged on to web site with several...
3
by: Andy | last post by:
Hi folks, I have a customvalidator control that works properly if it isn't contained in an ASP:TABLE. But, when I place it inside an ASP:TABLE, I find that _ServerValidate doesn't get fired,...
1
gagandeepgupta16
by: gagandeepgupta16 | last post by:
Hi I am working on an entry form using validation controls in ASP.NET. I have two controls which requires custom validators, no issue in using plain custom validators. But when i am using...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.