c# - WebControl's constructor does not have correct attribute value -


i want constructor of webcontrol able access value of isspecial (from html). however, it's false. assume it's false in constructor because doesn't read value until after constructor method over. there way have knows correct value of isspecial in constructor?

c#:

[defaultproperty("text")] [toolboxdata("<{0}:webcontrolexample runat=server></{0}:webcontrolexample>")] public class webcontrolexample: webcontrol, inamingcontainer {     private readonly int[] goodies;      public webcontrolexample()     {         if (this.isspecial)         {             goodies = new int[24];         }         else         {             //always reaches here             goodies = new int[48];         }     }      private bool isspecial= false;     public bool isspecial     {         set         {             this.isspecial= value;         }     } } 

html:

<xyz:webcontrolexamplerunat="server" id="webcontrolexample" isspecial="true" /> 

this isn't great solution, if have have readonly array, have two readonly arrays , wrap them in accessor:

[defaultproperty("text")] [toolboxdata("<{0}:webcontrolexample runat=server></{0}:webcontrolexample>")] public class webcontrolexample: webcontrol, inamingcontainer {     private readonly int[] goodies = new int[48];     private readonly int[] goodiesspecial = new int[24];      private bool isspecial= false;     public bool isspecial     {         set         {             this.isspecial= value;         }     }      private int[] goodies     {          {return isspecial ? goodiesspecial : goodies;}     } } 

but haven't stated 1. why need 2 different-sized arrays or 2. you're doing them.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -