Usercontrol losing Viewstate across Postback

Posted by Robert W on Stack Overflow See other posts from Stack Overflow or by Robert W
Published on 2010-03-29T14:22:21Z Indexed on 2010/03/29 15:03 UTC
Read the original article Hit count: 607

Filed under:
|
|
|

I have a user control which uses objects as inner properties (some code is below).

I am having trouble with setting the attribute of the Step class programmatically, when set programmatically it is being lost across postback which would indicate something to do with Viewstate (?).

When setting the property of the Step class declaratively it's working fine.

Does anybody have any ideas of what this code be/what's causing it to lose the state across postback?

public partial class StepControl : System.Web.UI.UserControl
{
    [PersistenceMode(PersistenceMode.InnerProperty)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [NotifyParentProperty(true)]
    public Step Step1 { get; set; }

    [PersistenceMode(PersistenceMode.InnerProperty)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [NotifyParentProperty(true)]
    public Step Step2 { get; set; }

    protected void Page_Init(object sender, EventArgs e)
    {
        AddSteps();
    }

    private void AddSteps() { }
}

[Serializable()]
[ParseChildren(true)]
[PersistChildren(false)]
public class Step
{
    [PersistenceMode(PersistenceMode.Attribute)]
    public string Title { get; set; }

    [PersistenceMode(PersistenceMode.Attribute)]
    public string Status { get; set; }

    [PersistenceMode(PersistenceMode.InnerProperty)]
    [TemplateInstance(TemplateInstance.Single)]
    [TemplateContainer(typeof(StepContentContainer))]
    public ITemplate Content { get; set; }

    public class StepContentContainer : Control, INamingContainer { }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET