title: Unable to cast object of type 'System.String' to type 'System.Web.UI.Control'
body: <p>I got stuck here,</p>
  
  <p>i have dynamic table that i want to print. So i make session to pass it into web control.
  Unfortunately, it doesn't  run smooth. </p>
  
  <p>Here are my code :</p>
  
  <pre><code>protected void bt_print_click(object sender, EventArgs e)
  {
      StringWriter sw = new StringWriter();
      HtmlTextWriter w = new HtmlTextWriter(sw);
      panelBilling.RenderControl(w);
      string s = sw.GetStringBuilder().ToString();
      Session["ctrl"] = s;
  
      ClientScript.RegisterStartupScript(this.GetType(), "onclick", "&lt;script language=javascript&gt;window.open('Print.aspx?rep=1','PrintMe','height=680px,width=1024px,scrollbars=1');&lt;/script&gt;");
  
  }
  </code></pre>
  
  <p>And the Print.aspx.cs code:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      Control ctrl = (Control)Session["ctrl"];
      PrintHelper.PrintWebControl(ctrl);
  }
  </code></pre>
  
  <p>I always got error message : </p>
  
  <blockquote>
    <p>"Unable to cast object of type 'System.String' to type
    'System.Web.UI.Control'."</p>
  </blockquote>
  
  <p>on </p>
  
  <pre><code>(Control)Session["ctrl"]
  </code></pre>
  
  <p>part. I have use this method many time and no problems before. Anyone has any idea? Thanks.</p>