Dropdown item selection not updated from db/HtmlInputHidden control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brendangallaghe
    New Member
    • Jan 2011
    • 5

    #1

    Dropdown item selection not updated from db/HtmlInputHidden control

    I have have a .net (3.5) user location dropdown menu (System.Web.UI. WebControls.Dro pDownList) 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

    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.


    The sequence is a follows:

    1. In the Page_Load, I set the value of hidden field (System.Web.UI. HtmlControls.Ht mlInputHidden) called hidUserName from

    HttpContext.Cur rent.User.Ident ity.Name;

    2. Get the OfficeLocationI D from the database
    3. Set the value of a hidden field (System.Web.UI. HtmlControls.Ht mlInputHidden) called hidUserLocation ID.Value
    4. Set the value of the ddlLocation menu SelectedValue to the value of hidUserLocation ID.Value


    Code:
    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);
            }
        }
    Last edited by Niheel; Jan 11 '11, 08:57 PM. Reason: code tags
  • brendangallaghe
    New Member
    • Jan 2011
    • 5

    #2
    I have resolved this issue myself. Issue closed.

    Comment

    Working...