AJAX DB Lookup

  • Thread starter Thread starter just4fun6969
  • Start date Start date
J

just4fun6969

I'm not sure if this is the right place for this question...

But I'm building a web application that will pre-populate a form using
AJAX and minimual user input. The problem is I want to make one
database call and to get all of the variables and then populate the
form.

However, I can't seems to find a way to pause execution of the
javascript until the method from the c# application has been returned.

Any ideas?
 
It's a web based data entry application and I'd rather not have the
delay associated with a post-back.

So far, what I'm using is:

var behavior1 = $find('dpLName');
behavior1.populate(myValue);
setTimeout("populateRemainder(myValue)",500);

The server side method for the DynamicPopulationExtender sets server
side variables then the other DynamicPopulationExtenders access those
server-side variables in the populateRemander function.

Essentially, I am forcing a delay to allow the behavior1 object to
populate. What I'd like to do is somehow call the behavior1.populate
method in a non-async way, that is, wait to proceed until it has
finished executing, but I don't know how to do that.
 
I think I am still missing something.

Does behavior1 populate the same, on initial form load, every time? If so, I
would do that server side. You have to go to the server to paint the form
the first time anyway.

If this is a form that shows up magically, you can still prepulate on the
server. You simply hide the form. But, I doubt that is your issue, as AJAX
would work fine even if you did not originally paint the form on initial
page load.

As for the question, there are certainly ways to add a stall into a
JavaScript routine. Even better, you create the intial load with a callback
and finish painting the form only when there is a return from the routine
that loads the behavior. If you want to see an example, there are things
like MooTools, which has a loading mechanism or the one MapQuest uses (which
escapes me at the moment). If you don't want the entire library, just grab
the code ... it is open source.

My point, however, is if the form gets loaded right after the person gets
the page from the server, just load it from the server. There is no rule
that states an AJAX page must use AJAX for initial load. If you don't have
to use AJAX for load, I would not kludge up a delay just so you did not load
from the server.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
Hey Cowboy - Thanks for your response and help!

The part I omitted, making it harder for you to follow, is this:

A. The form renders with empty fields
(name,address,phone,field1,field2, etc.)
B. The data entry person then types the information from a printout
and submits the form.
C. We have some of the information already available (say name and
address info)
D. When the data entry person enters the phone number - I want the
form (originally conceived as using AJAX) to look up the phone number
in the DB and populate name, address,city,state and zip so it saves
the data entry person some time.

Here's where I think my limited knowledge of AJAX is hurting me.... I
see four ways to solve the problem.

1. User submits the form and server side populates name and address -
this was rejected because the submit intrupts the data entry flow
2. use AJAX and DynamicPopulateExtender on name, addess,
city,state,zip. This was rejected because it would require 5 separate
DB look ups.
3. use AJAX and DynamicPopulateExtender return all 5 data elements to
a hidden input box and use javascript to parse and populate
name,address,city,state and zip - just didn't want to start down this
road yet...
4. My current approach - User AJAX and DynamicPopulationExtenders. The
server method on one field, say name, queries the DB and populates
server side variables for address, city,state, and zip. It returns
name. Then the DynamicPopulationExtender Server Side methods for
address, city, state, and zip just return the prepopulated server side
variable.

#4 works but it isn't fluid because of my arbitrary timeout. The
problem with #4 is getting it to execute the DynamicPopulationExtender
methods for address,city, state, and zip only AFTER the server side
method for name has completed. I think your suggestions are for an
initial page load solution??

I'm still trying to get it right :-)
 
You can have it so they enter the phone number and then submit. The data
transport can still be AJAX, but you are taking the "round trip" without a
repaint of the screen. I will have to think about the stall issue, as I am
sure there is a way around this. Since you are doing everything in
JavaScript with AJAX, you are a bit limited on what you can do.

When you say this is data entry, do you mean these are all internal users
(ie, company employees or contractors, not necessarily only those working in
the office)? If so, the web app direction may not be the best approach. You
can set up a click once windows app, for example. If delivery has to be web,
Silverlight is also an option, although I would head to Silverlight 2, which
is still beta. Either of these approaches gives a better data entry
experience.

I had to write an app years ago that was data entry. All JavaScript for the
data entry portion and I ended up using XmlHttp (the precursor of AJAX) for
my roundtripping. SO, I understand the pain. If you can get buy off on a
windows app, even if it has to be delivered via the web (click once) or a
more full featured browser plug in (Java applet, Flash, Silverlight), you
will find it easier for the data entry people. Of course, management does
not always give the option. :-)

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 
Back
Top