views:

900

answers:

1

Hi, I have multiple drop down lists on a page. They all contain list of countries. So in the background I am getting countries from database and caching them. I would like to populate those drop down lists from another thread. I am also using AJAX controls so I wanted that it all happens at the same time. And also after a user selects a country I want that towns from that country show to the user, and I want that getting towns happens also in another thread so that user can fill other controls while the list is not yet loaded.
I have read somewhere that I should give Page as a parameter to that thread and then find that drop down lists and populate them. But that is not working.

Here is a function that is called when another thread starts:

protected void GetCountries(object o)
{
    if (Session["Countries"] == null)
    {
        Session["Countries"] = CountryRepository.Instance.GetAll();
    }
    if (o is Page)
    {
        Page p = (Page)o;
        DropDownList ddl = (DropDownList)p.FindControl("ddlCountry");
        ddl.DataSource = Session["Countries"] as List<Country>;
        ddl.DataTextField = "Name";
        ddl.DataValueField = "Id";
        ddl.DataBind();
    }
}

Anyone sees a possible problem? Or perhaps my whole concept is wrong? Does anyone have an idea how to solve this problem?

+1  A: 

Take a look at the CascadingDropDown Extender from the ASP.NET AJAX Control Toolkit. It uses web services to populate the dropdowns, so it can operate asynchronously (which I believe is what you're after).

Dave Ward
+1, although I prefer a solution that utalises client and server caching for this sort of data.
AnthonyWJones