AJAX (javascript help) - ASP.NET(C#)

T

Trip

Please if someone can help me !!!

I need client and server code(principle based on AJAX) for next problem:

i have 3 <select> tags on html page.(it must be NO page reload(callback)
only select(controles) regeneration !!!)
In the first <select> goes countries, which must be pulled from some kind
of database (whichever you want).
after that if i select some country, second <select> must be filled with
regions of that country, and when i select some region than third <select>
must be filled with cities from that region.

conclusion: i need javascript code for html document and server .net code
which returns data based on xmlhttp request object which i send to him.

comment: please don't send links to other sites which has some solution
based on .net wrappers, or php/JAVA code !!! It's doesn't help me - I need
exactly what i wrote.


Thank you !
 
M

Mr Newbie

Just 'Skim-Read' that article and it looks like a good one. I must try it
out when I get a chance as it seems as if this is gaining popularity given
the number of AJAX related posts and references which I've seen around of
late.

Regards - Mr N . . .
 
T

Trip

article is good, and i already almost solve my problem with AJAX.NET
wrapper when my boss says that I MUST manualy write javascript and server
code. he doesn't want wrapper. stupid, but.. he is boss.
 
P

Paul Glavich [MVP ASP.NET]

Well there is no way I am going to write your entire solution for you, so
here is some code to make an async call using the XmlHttpRequest object so
that you can write all your own routines. The rest of the stuff like filling
in the list data, I am sure you will be able to work out.

function MakeXMLHTTPCall()
{
var xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
if (xmlHttpObj != null)
{
xmlHttpObj.Open("GET",http://YourServer/YourServerPage.aspx, true);

// Assign a function to be used as the callback to be called when the
async call is complete.
xmlHttpObj.onreadystatechange = function()
{
if ( xmlHttpObj.readyState == 4 )
{
alert("Your request has completed its async operation. Your data
returned was " + xmlHttpObj.responseXML);
// Or you can use the responseText property
alert("Your request has completed its async operation. Your data
returned was " + xmlHttpObj.responseText);
}
}
xmlHttpObj.send(SomeArgument); // This can be null if no arguments are
required.
}
}

This will asynchronously request the output of the "YourServerPage.aspx"
page and return it to the function defined here for your manipulation. This
would be where you fill the listbox/dropdowns based on return data.
 
L

lportx

This solution will work in I.E. However if you are concerned about
Safari or Mozilla browsers you need to to get the XMLHttpObject a
different way. Its useful to write a wrapper factory function and then
access it when you need the object:

// Cross-Browser support factory function
function getHTTPObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}

// Usage
var HTTP = getHTTPObject();

Regards,

Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top