473,385 Members | 1,757 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.

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 3516
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: 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
jinu1996
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...

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.