How to retrieve a value after calling loadState?

3 posts, 0 answers
  1. Lee
    Lee avatar
    11 posts
    Member since:
    Jul 2015

    Posted 24 Mar Link to this post

    I'm trying to achive this scenario.

     

    I have a RadDropDownTree using persistence framework to retain the selected combo value. My code is below.

    When a user visits my page, the persistence framework correctly pulls the correct RadDropDownTree1.SelectedValue from the cookie and restores the RadDropDownTree as I expect. The issue is when I try to read RadDropDownTree1.SelectedValue after calling loadState in my code below (highlighted in bold) the value is always empty "". I presume this is due to a timing issue? What would be the correct way to do this?
     
     
    private static readonly string CookieName = "TestCookie";
     
    protected void Page_Init(object sender, EventArgs e)
    {
        RadPersistenceManager1.StorageProviderKey = CookieName;
        RadPersistenceManager1.StorageProvider = new CookieStorageProvider(CookieName);
    }
     
     
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
     
     
            if (Request.Cookies[CookieName] != null)
            {
                RadDropDownTree1.DataBind();
                RadPersistenceManager1.LoadState();
                Label1.Text = RadDropDownTree1.SelectedValue;
            }
        }
         
    }
     
    protected void RadDropDownTree1_EntriesAdded(object sender, DropDownTreeEntriesEventArgs e)
    {
        //save selections
        RadPersistenceManager1.SaveState();
    }
  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 29 Mar Link to this post

    Hello Lee,

    Unfortunately, the state of the control is not yet applied at the stage of the Page's lifecycle, where you aim to extract its SelectedValue.

    For this reason, I would suggest you to use the Page_PreRenderComplete event handler, as demonstrated below:

    protected void Page_PreRenderComplete(object sender, EventArgs e)
    {
        Label1.Text = RadDropDownTree1.SelectedValue;
    }

    Hope this would help.

    Regards,
    Nencho
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lee
    Lee avatar
    11 posts
    Member since:
    Jul 2015

    Posted 29 Mar Link to this post

    Perfect, thanks for your help
Back to Top