Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Callback problem 1

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
I have a .ASPX page, code behind it and I have a class containing a library of data validation functions. I call many of these data validation functions from the code behind.

One of the data validation functions in the library loops through an array of validation rules and performs various "standard" validations (e.g. valid date, valid currency, value in range etc).

What I'd like to be able to do within the function is, if I encounter a "non-standard" validation rule that I don't recognise (e.g. postcode validation), then I'd like to "callback" a function within the original code behind the .ASPX page to process that one rule within the array and continue to process the loop.

How might I go about this please? Do I need to use Delegates somehow? Or can I pass through a reference to the .aspx page so that the code within it can be referenced by the library somehow?

Apologies for dominating the forum somewhat.:)
 
Just to clarify, these non-standard functions that you need to call will actually be called from the server, not the client i.e the user will have already posted the form back to the server?

If so, then it's not really a callback as such (that terminology is normally used when a client makes a request to the server to update part of the rendered page i.e. an AJAX request). In this case, as you already at the server, you can just call your validation routine (I'm not sure whether you will have written these yourself or whether it is a 3rd party library) and have them return their result before you decide whether to continue or not.

If they are to be called in an AJAX approach, then there are a few different routes you could take, but I'll wait for your response before we see what approach would be best for you.



Mark,

Darlington Web Design
Experts, Information, Ideas & Knowledge
ASP.NET Tips & Tricks
 
Thanks Mark - you are correct, this is not a callback in that sense, sorry. This is my own code, not a third party.

I suppose what I need to know is how to reference back to the original page from the library.

So, in fred.aspx I have an 'Imports GvlLib' and in GvlLib.vb a routine called GeneralValidate. So from fred.aspx I can call GeneralValidate no problem.

In fred.aspx I also have a routine called LocalValidate which I want to call from GeneralValidate and I don't know how to do that.

Like one of my earlier threads, this need not be my final solution but it all helps me get a grasp of what's possible and how to do it. Sorry this is .NET 101 stuff I guess.
 
OK, that's at least clarifies where you are coming from.

In fred.aspx I also have a routine called LocalValidate which I want to call from GeneralValidate and I don't know how to do that.
This is where the real issue lies and I don't think you should actually go down that route (but it is an option). As far as "GeneralValidate" is concerned, it has it's own logic to do and anything specific to a local page it probably isn't interested in.

So, you have a few potential options I think:

1. Inject some dependency into "GeneralValidate" that runs some "local" code
2. Modify "GeneralValidate" to include any new "local" validation routines that you think are useful
3. Have an intermediate validation class that includes "local" validation and apply that before calling "GeneralValidate"
4. Make your local page call the local function before calling the "GeneralValidate" one

Option #1 could be quite tricky. There are some 3rd party frameworks that help automate this and I can dig one out for you if necessary.

Option #2 could be a good option, but it really depends on how specific those functions are and whether you can make them more generic.

Option 3# could also be a good option, especially if you think you could make use of those local functions throughout this one application.

Option #4 would be good in a scenario where they really are specific to one page.

It's quite difficult to tell you which is the best route to go down as it's really up to what you think and which one best suits your project, but hopefully this gives you a few ideas.



Mark,

Darlington Web Design
Experts, Information, Ideas & Knowledge
ASP.NET Tips & Tricks
 
OK Mark, thanks for going to such lengths on my behalf. You're probably right - i.e. that I shouldn't really be doing it. I was just interested as it's a similar approach to what I've taken in VB6 projects before - naughty as it may be!

What I will do is build a list of unrecognised validation rules while in GeneralValidate (which really has to be run first to trap the "silly" problems like entering alpha in numeric item) and return that to fred.aspx which will then call its local logic to process the unresolved items. So this is close to your option 4 but sequence swapped.
 
In theory yes - although the example is one of the more trivial ones.

To be honest I've tended to shy away from client-side validation in the past because of virtually zero knowledge of Javascript (can I face another learning curve?) and awareness that any VbScript validation would not be recognised by browsers outside IE.

Am I out of touch? If so, I'm open to receiving more knowledge but please be gentle!
 
Yes, I'd say you are a bit but that's not necessarily a bad thing and I think you'll probably find that the learning curve is much, much simpler now thanks to frameworks like JQuery.

I use a JQuery Validation Plugin that makes it easy to implement client side validation without actually getting that involved with any javascript (have a look at the example on the page that shows some simple validation by simply adding a class name to whichever element you want to validate).

Mark,

Darlington Web Design
Experts, Information, Ideas & Knowledge
ASP.NET Tips & Tricks
 
OK thanks for that. I will take a look when I have the luxury of time to do so. I'll keep the server-side validation until I've got the application mostly working.

In the meantime I'm fighting Visual Studio which claims I have build errors but clearly thinks it's too much trouble to actually tell me what they are.

So I then think I should install service pack. Am currently a good 2 hours into that, sigh. Microsoft are clearly out to ruin my day - not for the first time. I sense I'm wandering off topic...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top