While print data from repeater control in asp.net with C#
<p>I got this error while i use to print data from repeater</p>

<p>"RegisterForEventValidation can only be called during Render();"</p>

<p>I already set EnableEventValidation="false" in page directive
and also in web.config of my application inside page tag</p>

<p>Here is the code which I use for that</p>

<pre><code>public static void PrintWebControl(Control ctrl, string Script)
{

    StringWriter stringWrite = new StringWriter();

    HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

    if (ctrl is WebControl)
    {

        Unit w = new Unit(50, UnitType.Pixel);

        ((WebControl)ctrl).Width = w;

    }

    Page pg = new Page();      


    if (Script != string.Empty)
    {

        pg.RegisterStartupScript("PrintJavaScript", Script);

    }

    HtmlForm frm = new HtmlForm();

    pg.Controls.Add(frm);

    frm.Attributes.Add("runat", "server");

    frm.Controls.Add(ctrl);

    string scr = "&lt;script&gt;function window.onafterprint(){history.back(1);}&lt;/script&gt;";

    htmlWrite.Write(scr);



    pg.DesignerInitialize();

    pg.RenderControl(htmlWrite);       




    string strHTML = stringWrite.ToString();

    HttpContext.Current.Response.Clear();

    HttpContext.Current.Response.Write(strHTML);

    HttpContext.Current.Response.Write("&lt;script&gt;window.print();&lt;/script&gt;");

    HttpContext.Current.Response.End();

}
</code></pre>
