asp.net中繼器控制打印數據的同時,我使用從中繼打印數據I得到這個錯誤雖然從與C#
「RegisterForEventValidation只能在渲染()被調用;」
我已經在頁面指令 設置EnableEventValidation =「假」,並在我的網頁標籤內的應用程序的web.config文件
這裏是我使用該
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 = "<script>function window.onafterprint(){history.back(1);}</script>";
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("<script>window.print();</script>");
HttpContext.Current.Response.End();
}
請發表您的代碼。 – Lazarus 2010-12-08 12:59:41