hello,
I've a empty dropDownList. When it is clicked, i want to go to the server and fill it with the appropriate data.
My problem is that dropDownList has few events and has no
click event.
I thought about catching the event as client event and then call the server method that fills the data (is it possibale and how?).
I tried with this (at the code behind) and it works ok, to go to the client when the dropdown is clicked:
DropDownApp.Attributes.Add("onclick", "Fill(this);");

but I can´t figure out how to fill the dropdown from client-side.

other ideas (with example) will be highly appreaciated.
thanks!!

Why aren't you filling the dropDownList server-side, prior to delivery to the client?

I go into detail about the client-server nature of ASP.NET with these articles.

I have to fill it just when the user clicks on the combo...I don´t know how to do this, and as the dropdownlist control doesn´t have the onclick event, I thought using the client event.

Yes, but, why? What I'm telling you is that this approach is unconventional. If you have enough information to fill the list when someone clicks it, you have enough information to fill it before it is clicked.

My suggestion is, the flaw is with your approach, not with the dropdownlist.

So again:

Why aren't you filling the dropDownList server-side, prior to delivery to the client?

You cannot fill the list client-side, unless the data to fill it is present client-side. How would the data be available? Only if you put it there, server-side. And if you can do that... why not just fill the list?

Yes, I should fill the combo with a dataset.
Yes, sure...but is the way the client wants...Also because the are two combos(in addition to mine), and each sql query takes a lot of time...so, if I fill the two combos simultaneously, it would take too much time.

More time than it would take to fill them slowly, one at a time, with server round-trips throw in? NO WAY.

Plus, you can likely combine your queries to return all the results in a single recordset. You don't have to use a dataset, you can can do all your queries at page load, store the results someowere (dataset, arraylist, etc.) and bind that to your dropdowns.

Trust me: you cannot do this "client-side", because a client script cannot access a database, do a query, bind to a server-control, etc.

You can either code a JavaScript "submit()" to go fetch the data via server-side code, which is slower than just doing it in the first place, or you can code something using AJAX to retrieve the data (in ASP.NET they call it a "Script CallBack"), also slower than doing it upfront.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.