title: What is the proper way to maintain state in a custom server control?
body: <p>This works, but is it the proper way to do it???</p>
  
  <p>I have a custom server control that has an [input] box on it.  I want it to kinda mimic the ASP.NET TextBox, but not completely.  When the textbox is rendered i have a javascript that allows users to select values that are then placed in that input box.</p>
  
  <p>I have a public text property on the control.  In the get/set i get/set the viewstate for the control - that part is easy, but when the control is populated via the javascript, the Text get is not actually called, what is the proper way to set this exposed property using JavaScript (or even if the user just types in the box) ?</p>
  
  <p>Edit:
  In the OnInit i ensure the state is maintained by reaching into the form values.</p>
  
  <pre><code>    protected override void OnInit(EventArgs e)
      {
          base.OnInit(e);
  
          if (HttpContext.Current.Request.Form["MyInputBoxValue"] != "")
          {
              ViewState["MyInputBoxValue"] 
                 = HttpContext.Current.Request.Form["MyInputBoxValue"];
          }
      }
  </code></pre>
  
  <p>Then to get the value actually back in place in the HtmlTextWrite, i do this:</p>
  
  <pre><code>protected override void RenderContents(HtmlTextWriter output)
  {
  
          // There is an input control here and i set its value property
          // like this using the Text internal defined.
          output.Write("&lt;input value=" + Text + "&gt;.....
  
  }
  </code></pre>
  
  <p>thanks</p>