Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 705335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:02:31+00:00 2026-05-14T04:02:31+00:00

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

  • 0

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?

ASPX Page

    <uc1:StepControl ID="StepControl1" runat="server">
        <Step1 Title="1. Select your Products" Enabled="true">
            <Content>

                <div class="clearfix">
                    <div class="floatRight">
                        <asp:Button ID="btnGoToStep2" 
                        runat="server" 
                        Text="Next" 
                        CausesValidation="false" 
                        OnClick="btnGoToStep2_OnClick" />
                    </div>
                </div>

            </Content>
        </Step1>
        <Step2 Title="2. Select your Features">      
            <Content>

                <div class="clearfix">
                    <div class="floatLeft">
                        <asp:Button ID="btnBackToStep1" 
                        runat="server" 
                        Text="Back" 
                        CausesValidation="false" 
                        OnClick="btnBackToStep1_OnClick" />
                    </div>                    
                    <div class="floatRight">
                        <asp:Button ID="btnGoToStep3" 
                        runat="server" 
                        Text="Next" 
                        CausesValidation="false" 
                        OnClick="btnGoToStep3_OnClick" />
                    </div>
                </div>                    

            </Content>
        </Step2>                     
    </uc1:StepControl>

ASPX code behind

    protected void btnGoToStep2_OnClick(object sender, EventArgs e)
    {
        StepControl1.Step1.StatusText = "4 Products Selected";
    }

    protected void btnBackToStep1_OnClick(object sender, EventArgs e)
    {
        // StatusText (of Step1) gets lost at this point. 
    }

User control code behind

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 { }
}
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:02:31+00:00Added an answer on May 14, 2026 at 4:02 am

    I think the string you set never makes it to the ViewState. I am a bit short of terminology here (read: I do not know the terminology) but I think your attribute [PersistenceMode(PersistenceMode.Attribute)] only tells ASP.NET it should look for an attribute called “Status” in the markup (ASPX-file) and if it finds one, set the property Status to its value (actually I am wondering where exactly it is put in your example?). It does not tell anybody to put something into ViewState though.

    If you would define your property Status along these lines

    [PersistenceMode(PersistenceMode.Attribute)]
    public string Status
        {
            get
            {
                object o = ViewState["Status"];
                if(o != null) {
                    return (string)o;
                }
                return string.Empty;
            }
            set
            {
                ViewState["Status"] = value;
            }
        }
    

    you should be better off.

    For the rest of it I am not sure if you have to call TrackViewState() in UserControls or even override SaveViewState and LoadViewState but I do not think so. If this would be the case the following links might help:

    • Microsoft: Understanding ASP.NET View State
    • ASP.NET Forum: How to preserve ViewState in user control
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user control...and the base page(s) which uses this user control has
I have two problems with an own user control which uses bitmaps: It flickers
I have a user control that displays objects of a client-declared type with some
I have a WPF application which uses a WPF user control. The user control
I have an application that uses Caliburn.Micro. My View contains a user control which
I am having problem in accessing user control properties from page. I have usercontrol
I have a ASP.NET user control which hosts a 'HtmlImage'. The src attribute is
I have a user control which displays the currently logged in user's name. I
I have a user control which is 2 RadCombos cascaded. I'm trying to add
I have a user control which has a DateTimePicker overlaid with the single line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.