1

I have a custom control that inherits from PeopleEditor in my WebPart. In the custom control I have a custom property:

public string MyProperty
        {
            get
            {
                string text = (string)ViewState["myKey"];
                if (text != null)
                    return text;
                else
                    return string.Empty;
            }
            set
            {
                ViewState["myKey"] = value;
            }
        }

I set this property while OnInit of my WebPart. But after post back of this control ViewState comes without my property, it even doesn't contain myKey in the Keys.

Do you have any ideas how to creat a custom property which will not be lost after post back?

2
  • Do you use that by visual webpart in sandboxed solutions? I remember that the viewstate not work in sandboxed webparts.
    – Sascha
    Commented Apr 11, 2013 at 10:05
  • No, I use it in a visual webpart in a farm solution.
    – alisa
    Commented Apr 11, 2013 at 11:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.