472,959 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Need help programming a custom validator

Hello

Here's my basic problem:

On my asp.net form page I have a DetailsView (default mode=edit) bound
to a AccessDataSource control. Users can successfuly update a databound
template field, but I wanted to add a custom validator to check that
the account number they are entering exists in a table in the Access
Database.

I've tried adding another AccessDataSouce (which lists all the accounts
numbers in the database) and attempted to programmatically check if the
entered account exists; but as I've only just moved from classic ASP to
ASP.NET I get the feeling I'm coming at this from the wrong angle.

Basically what I need help with is writing the VB code for the custom
validator. Any help is greatly appreciated.

Rich

Jan 22 '07 #1
3 3495
hi rich,
you need to add an event handler to the detailsview for whichever actions
you want to validate on, e.g. update / insert etc.

take a look at the events listed for this class on msdn2:
http://msdn2.microsoft.com/en-gb/library/keezbt7k.aspx
then look at ItemInserting as an example. this event is raised before the
insert actually takes place, so you can put your code in here, check if it's
all good, and if there are any problems you can set e.Cancel = true and the
insert will not go through. you can display an error message etc.

hope this does it for you. you'll find the SDK class library reference is
your best friend when you are new to .net... and possibly 5 years later if
you're still learning .net like me :)

tim
"Rich Squid" <pl*********@gmail.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
Hello

Here's my basic problem:

On my asp.net form page I have a DetailsView (default mode=edit) bound
to a AccessDataSource control. Users can successfuly update a databound
template field, but I wanted to add a custom validator to check that
the account number they are entering exists in a table in the Access
Database.

I've tried adding another AccessDataSouce (which lists all the accounts
numbers in the database) and attempted to programmatically check if the
entered account exists; but as I've only just moved from classic ASP to
ASP.NET I get the feeling I'm coming at this from the wrong angle.

Basically what I need help with is writing the VB code for the custom
validator. Any help is greatly appreciated.

Rich
Jan 22 '07 #2
Hi Tim

Thanks for the heads up.

My problem is not knowing where to put the code, but how to write the
code. I've tried putting the validation in the "ItemInserting" event of
the DetailsView (as you suggested); in the "Updating" event of the
AccessDataSource which the DetailsView is bound to; and finally (as I
mentioned in my initial post) in the code of a CustomValidator.

The code I am trying to write needs to check to see if the account
number the user is attempting to enter is valid. This can be worked out
by seeing if is value exists in another 'accounts' table which lives in
the Access Database. If the account is not found then I need to halt
the update (as you suggested) and let them know that the account is
invalid - which is why I was using a custom validator.

I'll bookmark the SDK class library as I'm sure I'll be visiting it
again in the future!! Thanks.
For me asp.net seems to be one of those "ahhh - that's how you do it"
experiences.

Thanks again,

Rich

Tim Mackey wrote:
hi rich,
you need to add an event handler to the detailsview for whichever actions
you want to validate on, e.g. update / insert etc.

take a look at the events listed for this class on msdn2:
http://msdn2.microsoft.com/en-gb/library/keezbt7k.aspx
then look at ItemInserting as an example. this event is raised before the
insert actually takes place, so you can put your code in here, check if it's
all good, and if there are any problems you can set e.Cancel = true and the
insert will not go through. you can display an error message etc.

hope this does it for you. you'll find the SDK class library reference is
your best friend when you are new to .net... and possibly 5 years later if
you're still learning .net like me :)

tim
"Rich Squid" <pl*********@gmail.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
Hello

Here's my basic problem:

On my asp.net form page I have a DetailsView (default mode=edit) bound
to a AccessDataSource control. Users can successfuly update a databound
template field, but I wanted to add a custom validator to check that
the account number they are entering exists in a table in the Access
Database.

I've tried adding another AccessDataSouce (which lists all the accounts
numbers in the database) and attempted to programmatically check if the
entered account exists; but as I've only just moved from classic ASP to
ASP.NET I get the feeling I'm coming at this from the wrong angle.

Basically what I need help with is writing the VB code for the custom
validator. Any help is greatly appreciated.

Rich
Jan 22 '07 #3
hi rich. glad to be of help.
the customValidator sounds like the best approach.
i could be wrong on this, but i think you may still need code in the
ItemInserting event, along the lines of:

if not Page.IsValid then
e.Cancel = true
end if

the OnServerValidate event of your CustomValidator should fire before the
ItemInserting event.
if it isn't working out for you, post what you have, aspx + codebehind, and
we can take a look at it.
thanks
tim
"Rich Squid" <pl*********@gmail.comwrote in message
news:11*********************@51g2000cwl.googlegrou ps.com...
Hi Tim

Thanks for the heads up.

My problem is not knowing where to put the code, but how to write the
code. I've tried putting the validation in the "ItemInserting" event of
the DetailsView (as you suggested); in the "Updating" event of the
AccessDataSource which the DetailsView is bound to; and finally (as I
mentioned in my initial post) in the code of a CustomValidator.

The code I am trying to write needs to check to see if the account
number the user is attempting to enter is valid. This can be worked out
by seeing if is value exists in another 'accounts' table which lives in
the Access Database. If the account is not found then I need to halt
the update (as you suggested) and let them know that the account is
invalid - which is why I was using a custom validator.

I'll bookmark the SDK class library as I'm sure I'll be visiting it
again in the future!! Thanks.
For me asp.net seems to be one of those "ahhh - that's how you do it"
experiences.

Thanks again,

Rich

Tim Mackey wrote:
>hi rich,
you need to add an event handler to the detailsview for whichever actions
you want to validate on, e.g. update / insert etc.

take a look at the events listed for this class on msdn2:
http://msdn2.microsoft.com/en-gb/library/keezbt7k.aspx
then look at ItemInserting as an example. this event is raised before
the
insert actually takes place, so you can put your code in here, check if
it's
all good, and if there are any problems you can set e.Cancel = true and
the
insert will not go through. you can display an error message etc.

hope this does it for you. you'll find the SDK class library reference
is
your best friend when you are new to .net... and possibly 5 years later
if
you're still learning .net like me :)

tim
"Rich Squid" <pl*********@gmail.comwrote in message
news:11**********************@l53g2000cwa.googleg roups.com...
Hello

Here's my basic problem:

On my asp.net form page I have a DetailsView (default mode=edit) bound
to a AccessDataSource control. Users can successfuly update a databound
template field, but I wanted to add a custom validator to check that
the account number they are entering exists in a table in the Access
Database.

I've tried adding another AccessDataSouce (which lists all the accounts
numbers in the database) and attempted to programmatically check if the
entered account exists; but as I've only just moved from classic ASP to
ASP.NET I get the feeling I'm coming at this from the wrong angle.

Basically what I need help with is writing the VB code for the custom
validator. Any help is greatly appreciated.

Rich
Jan 23 '07 #4

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

Similar topics

8
by: Spartanicus | last post by:
The document at http://homepage.ntlworld.com/spartanicus/custom_dtd.htm uses a custom DTD, the w3c validator validates it but with this warning: "Unknown Parse Mode! The MIME Media Type...
1
by: Vinod I | last post by:
Hi Team, I made a custom validator control which is having 2 public properties. But after making dll & adding that to the ToolBox, I could not able to find these properties in Property Box. ...
5
by: Richard Payne | last post by:
Hi This is probably a newbie question but I can't seem to find a clear answer to the problem I have. I have created a Custom Validator control on my webform that works fine, but when I put...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
2
by: Alan Silver | last post by:
Hello, I have a custom validator on my page, and have the server-side code working fine. I want to add a client-side funtion as well, but am not sure how to wire it in so that it works with the...
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,...
0
by: tsw_mik | last post by:
I have created a custom control. It has: -label -button -list of textboxes -list of dropdownlists. I want to use a custom validator to perform some validation, but somehow I can't fo it. The...
1
by: Gonza | last post by:
Hi group, i'm trying to add a customvalidator control to a custom web control. The problem is i'm getting a "Unable to find control id..." exception. Here is the code: public class CuitTextBox :...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.