471,595 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 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 3433
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Richard Payne | last post: by
reply views Thread by Marek | last post: by
3 posts views Thread by Andy | last post: by
reply views Thread by tsw_mik | last post: by
1 post views Thread by Gonza | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.