1

i have a custom control i need to store the array collection in the view state. array collection is circular scales. How to proceed further ?

public class CircularGauge : WebControl
    {
private CircularGaugeProperties model = new CircularGaugeProperties();

private List<CircularScales> scales = new List<CircularScales>();
[Browsable(true)]
        [Bindable(true)]
        [Category("Circular Gauge Properties")]
        [Description("Scale values")]
        [JsonProperty("scales")]
        [MergableProperty(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public List<CircularScales> Scales
        {
            get
            {
                if (scales == null)
                {
                    scales = new List<CircularScales>();
                }
                return scales;
            }
        }
}

where circular scales have array collection as inner properties.then how can i need to bind the properties in the Circularscales for viewstate maintenance.

1 Answer 1

7
 public List<CircularScales> Scales
 {
     get
     {
         if (ViewState["scales"] == null)
         {
             return new List<CircularScales>();
         }
         return (List<CircularScales>)ViewState["scales"];
     }
     set
     {
         ViewState["scales"] = value;
     }
 }

Useful link about what viewstate is and how to use it corectly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.