Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
    
Do you use that by visual webpart in sandboxed solutions? I remember that the viewstate not work in sandboxed webparts. –  Sascha Apr 11 '13 at 10:05
    
No, I use it in a visual webpart in a farm solution. –  alisa Apr 11 '13 at 11:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.