title: Convert 'Control' to textbox and assign it a value
body: <p>I am trying to create a form. The form controls names are always going to be the same. However the type of control will change. For example, I have a control named "first_name". When the page is initialized, it retrieves data from a database stating what the type of control (TextBox, DropDownList or CheckBox); Then the form is dynamically created on the page. To keep the viewstate, I created the control in the OnInit method.</p>
  
  <pre><code>protected override void OnInit(EventArgs e)
  {
      Control first_name;
      string ControlType = GridView1.Rows[0].Cells[1].Text;
      switch (ControlType)
      {
          case("TextBox"):
              first_name = new Control() as TextBox; first_name.ID = "first_name"; this.Controls.Add(first_name);
              break;
          case("DropDownList"):
              first_name = new Control() as DropDownList; first_name.ID = "first_name"; this.Controls.Add(first_name);
              break;
          case("CheckBox"):
              first_name = new Control() as CheckBox; first_name.ID = "first_name"; this.Controls.Add("first_name");
              break;
      }
  }
  </code></pre>
  
  <p>Then I render the control to the page.</p>
  
  <pre><code>protected override void Render(HtmlTextWriter writer)
  {
      writer.Write("first_name: ");
      first_name.RenderControl(writer);
  }
  </code></pre>
  
  <p>Next, I try to assign values to the control. This is where I run into problems. I know that when it's declared globally, it is declared as a control and holds those values. </p>
  
  <p>Is there a way to declare it globally from within a function or to change the type of a control after it's been declared globally?</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      switch (first_name.GetType().ToString())
      {
          case ("TextBox"):
              first_name.Text = "Your First Name...";
              break;
          case ("DropDownList"):
              first_name.Items.Add("Jason");
              first_name.Items.Add("Kelly");
              first_name.Items.Add("Keira");
              first_name.Items.Add("Sandi");
              first_name.Items.Add("Gary");
              break;
          case ("CheckBox"):
              first_name.Checked = true;
              break;
      }        
  }
  </code></pre>
  
  <p>Please provide a way that I can accomplish this.</p>