Tuesday, June 07, 2005

AJAX DropDownList

Just recently, I published a new article in CodeProject about implementation of AJAX (Asynchronous Javascript and XML) in a dropdownlist.

AJAX DropDownList is a custom control, inherited from System.Web.UI.WebControls.DropDownList. What differs this control from the normal DropDownList is the ability to fetch data asynchronously in the background without requiring any postbacks. Thus, an AJAX DropDownList can be dynamically populated from the client side using Javascript. Moreover, AJAX DropDownList implements Observer pattern to 'listen' to the change event of another AJAX DropDownList, and to 'broadcast' its change event to the other AJAX DropDownLists. This feature allows us to create a group of dependent dropdownlists, where a change in the first dropdownlist will trigger change on the second dropdownlist, and subsequently trigger change on the third dropdownlist, and so on...

Please read
the article in Code Project for more details.

7 comments:

Unknown said...

hey,
i used this control of yours in a project but i am not able to populate the data into the dropdownlist.
i debugged the code and found it producing the same data but i always get a javascript error when loading the first dropdown.

i am using vb.net, is this an issue with that or should it work perfectly fine?

Enrico Elizar Samuel said...

Hi Buster,

It doesn't matter if you use VB.NET as long as the handler produces correct JSON string.

What kind of error do you get?

Anonymous said...

Hi Enrico,

Thank you for this helpful article that is on codeproject.

I am using it for my project but i have a problem about setting the selectedIndex of dropdownlist.

I modified the control and added the selectedItemValue property. But when i use this, it is not working properly.

At the first page loading the selected item can not be set. But when i refresh the page the selected item can be set.

Do you have any idea about this. Is it impossible that setting the selected item at the first page loading?

Thank for your help, and happy new year.

İdris Cin said...

Hi Enrico,

Do not you have any idea about above?

See you.

Unknown said...

Dear Sir
I am using your JSON drop down control in numbers, but evry time it is throwing me an error in the browser IE6, syntaxx error in this function and no drop down is getting filled up

function doReadyStateChange()
{if(xmlHttp.readyState==4)
{if(xmlHttp.status==200)
{eval('var d='+xmlHttp.responseText);if(d!=null)
{populateList(d);}}
else
{alert('There was a problem retrieving the data:\n'+xmlHttp.statusText);}}}

Anonymous said...

Hiya

I'd really like to use your AJAX DDL because it seems exactly what I'm looking for but....

.. I can't get it working in VS2005 :(

Any hints?

Cheers

Charbel_Zibara@hotmail.com said...

Dear sir,
regarding the Ajax DropDropList custom control,please note that i'm not able to link the dropdownlist as follow:
dp1 observe dp2
dp1 observe dp3
dp2 observe dp3
dp3 in that case is populated only when i choose dp2 and not with dp1.
i wanted to be populated either when selecting dp1 or dp2 based on the selection.can you help me please.thanks in advance.Regards