What should LoadStateFromStorage return when empty?

5 posts, 0 answers
  1. gpe
    gpe avatar
    1 posts
    Member since:
    Mar 2014

    Posted 04 Mar 2014 Link to this post

    I'm using the clean sample of a CookieStateStorageProvider from http://demos.telerik.com/aspnet-ajax/persistence-framework/examples/custom-storage-provider/defaultcs.aspx

    When the CookieStateStorageProvider tries is called upon a key it does not know, returning null leads to an exception in the PersistenceManager. The thing is that I don't want my view to have to check if this key is already existing or not. It makes more sense that only the CookieStateStorageProvider knows about how to store the state. But what should its method return when the key is not valid/existing?

    I tried returning null or String.Empty but none is appreciated my the PersistenceManager.
  2. Per
    Per avatar
    116 posts
    Member since:
    Jan 2008

    Posted 22 Sep 2014 in reply to gpe Link to this post


    There is a bug in the example.
    Replace "LoadStateFromStorage" with this and it will work...

        public string LoadStateFromStorage(string key)
          if (HttpContext.Current.Request.Cookies[StorageKey] == null)
            throw new PersistenceFrameworkStorageException("Unable to read cookie storage content. ");

          return DecompressString(HttpContext.Current.Request.Cookies[StorageKey].Value.ToString());

  3. DevCraft R3 2016 release webinar banner
  4. Vessy
    Vessy avatar
    1357 posts

    Posted 25 Sep 2014 Link to this post

    Hi Per,

    Thank you for your observation - we will update the example right away.

    As a sign of gratitude we have also updated your Telerik points accordingly.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  5. Gary
    Gary avatar
    6 posts
    Member since:
    Oct 2012

    Posted 09 Apr 2015 Link to this post

    The example has still not been updated.


  6. Daniel
    Daniel avatar
    4935 posts

    Posted 14 Apr 2015 Link to this post

    Hello Gary,

    Thank you for your suggestion. I'm afraid we could not modify the live demo to throw an exception.
    Also, we have an explicit check on the click of the Load button here:
    protected void LoadButton_Click(object sender, EventArgs e)
        if (Request.Cookies[CookieName] != null)

    As to the case you mentioned, it is possible to avoid the exception inside the state serialization provider if you have one. It would be something like this:
    public class YourStateSerializer : IStateSerializer
             public List<RadControlState> DeserializeCollection(string stateData)
                  if (String.IsNullOrEmpty(stateData))
                           return new List<RadControlState>();

    This will work if you return an empty string from the LoadStateFromStorage method in the storage provider.

    I hope this helps.


    See What's Next in App Development. Register for TelerikNEXT.

Back to Top
DevCraft R3 2016 release webinar banner