By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,083 Members | 1,608 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,083 IT Pros & Developers. It's quick & easy.

Need help programming a custom validator

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.