IIS 5 & IIS 6
Using Ajax with Classic ASP
Last post May 12, 2008 10:16 PM by MyronCope
May 11, 2008 11:43 AM|MyronCope|LINK
I have 2 comboboxes on an ASP page and I need the following behavior:
1. user selects a value on combobox1
3. the VBScript function queryDB() returns a recordset of records from the database
4. bind the recordset to ComboBox2
The main thing that I'm stuck on is part 2, using Ajax to call a VBScript function. I now know I have to use some kind of Ajax because the page cannot postback. Does anyone know how to do this? any code samples would be great.
also is it possible to use a recordset or do i have to return the data in xml form? I posted a similar question already but I am posting this because I realize that I did not mention Ajax in my other initial post and this is the key point that I need to
figure out, how to use Ajax with Classic ASP.
May 11, 2008 02:12 PMemail@example.com|LINK
ASP doesn't work like ASP.NET. Write the entire thing as ASP or move to ASP.NET. Frankly, it doesn't sound like you should need to shell to an external VBScript just to query a database anyway.
May 12, 2008 08:48 AM|MyronCope|LINK
The page is in classic ASP, I cannot change this.
Also, the requirement states that the page cannot refresh so I assume that I will have to implement some Ajax like coding there.
If you know of another way that I can accomplish this I would be thrilled to hear about it.
May 12, 2008 09:03 AM|tomkmvp|LINK
How much data are we talking about? One technique is to load all of the data at once into the client-side code of the page. Take a look at some of the examples here:
May 12, 2008 09:10 AM|MyronCope|LINK
not too much data but here is the situation:
ComboBox1 can be loaded during pageload.
but ComboBox2 values must be loaded when you change ComboBox2 because the values in ComboBox2 are dependent on what you choose in ComboBox1.
I guess you can think of it like this:
ComboBox1 could be states in the US. When you select a state it will show corresponding cities that are in that selected state in ComboBox2.
May 12, 2008 09:17 AM|tomkmvp|LINK
If you can't refresh then you have two options:
1) my link above on DHTML and data binding
2) AJAX. Have you seen this?
May 12, 2008 10:16 PM|MyronCope|LINK
thanks for your feedback. I got it working! I pretty much followed this page, their ajax tutorial is great, highly recommended:
I followed this exactly except for the asp page (think the example is called getcustomer.asp), instead of writing out the values I loop through each record and create a combobox option for each record returned:
Otherwise my code is the same (except of course changing page names and similar things).
If anyone wants to do this the link above should help you but let me know by posting here if you have any questions.