This is a migrated thread and some comments may be shown as answers.

How to retrieve a value after calling loadState?

2 Answers 61 Views
Persistence Framework
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 24 Mar 2016, 01:20 PM
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 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 29 Mar 2016, 12:54 PM
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.
0
Lee
Top achievements
Rank 1
answered on 29 Mar 2016, 01:40 PM
Perfect, thanks for your help
Tags
Persistence Framework
Asked by
Lee
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Lee
Top achievements
Rank 1
Share this question
or