Hi there

I have a .net (3.5) user location dropdown menu (System.Web.UI.WebControls.DropDownList) called ddlLocation, that when the user selects a location menu item that item is saved in a database table, so that the next time the user accesses the page the selection is pulled from the db table. The dropdown menu selection also updates the content of the treeview menu. This is all (db and treeview updates) done asynchronously using Ajax update panels, triggers etc.
I have tested that the entry is written to the table as I can see the table being updated with each selection. I have also tested that the dropdown menu item selection is populated correctly when the page is manually refreshed and when the browser is closed and re-opened on the page. However, when I make a dropdown menu item selection, and then click on the link from my favourites menu, the dropdown menu item selection is not updated with the selection I made, in fact, it reverts to the previous item selection (even though I see the correct selection in the db table). Strangely, when I make the dropdown menu item selection, then manually expand a node on the treeview, then click on the link from my favourites menu, the dropdown menu item selection is correctly populated when the page opens. How do I fix it so that the DropDownList selection saved in the db is correctly loaded when I click on the link from my favourites menu?

Any help on this would be greatly appreciated.


The sequence is a follows:

1. In the Page_Load, I set the value of hidden field (System.Web.UI.HtmlControls.HtmlInputHidden) called hidUserName from HttpContext.Current.User.Identity.Name;

2. Get the OfficeLocationID from the database
3. Set the value of a hidden field (System.Web.UI.HtmlControls.HtmlInputHidden) called hidUserLocationID.Value
4. Set the value of the ddlLocation menu SelectedValue to the value of hidUserLocationID.Value

protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {

		....

		hidUserName.Value = HttpContext.Current.User.Identity.Name;
		....
		GetUserInfo(hidUserName.Value);
		....
		PopulateLocationDropDown(hidUserName.Value);
		
        }

    }
private void GetUserInfo(string strUserName)
    {
        List<UserInfo> userInfoList;

        try
        {
            DBController dbc= new DBController();
            userInfoList = dbc.GetUserInfo(strUserName);
            UserInfo ui = userInfoList[0];
            hidUserTeamID.Value = Convert.ToString(ui.UserTeamID);
            hidUserLocationID.Value = Convert.ToString(ui.OfficeLocationID);  
      

        }

        catch (System.Exception eError)
        {
            throw new System.Exception(cannotGetUserInfo, eError);
        }
    }
private void PopulateLocationDropDown(string strUserName)
    {
        List<Location> locationList;
        List<UserInfo> userInfoList;
        try
        {
            DBController dbc= new DBController();
            locationList = dbc.GetLocations();
            ddlLocation.ClearSelection();


            for (int iIndex = 0; iIndex < locationList.Count; iIndex++)
            {
                Location loc = locationList[iIndex];
                ddlLocation.Items.Add(new ListItem(loc.LocationName, 

Convert.ToString(loc.LocationId)));
            }

            // Select the User's location option by default.
            userInfoList = dbc.GetUserInfo(strUserName);
            UserInfo ui = userInfoList[0];


            ddlLocation.SelectedValue = hidUserLocationID.Value;

        }
        catch (System.Exception eError)
        {
            throw new System.Exception(cannotGetLocations, eError);
        }
    }

I was able to resolve this issue myself. Issue closed.

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.