I have a spgridview and want to export its content to pdf. I am using itextsharp for the same. But error is encountered at rendercontrol call. I have already tried the solutions mentioned in the below thread. Question Also I have tried using
public override void VerifyRenderingInServerForm(Control control)
{
return;
}
but it doesnot work beacuse I am writing the code in usercontrol. Here is my ascx code.
<SharePoint:SPGridView ID="domainGridview" AllowPaging="false" runat="server" AutoGenerateColumns="False"
ShowHeader="true" ShowHeaderWhenEmpty="true" AllowSorting="True" GridLines="None" EnabledEventValidation="false">
<AlternatingRowStyle CssClass="ms-alternating" />
<Columns>
<SharePoint:SPBoundField DataField = "SiteName" HeaderText = "Team Site Name" SortExpression = "SiteName"></SharePoint:SPBoundField>
<asp:BoundField DataField = "SiteUrl" HtmlEncode="false" HeaderText = "Team Site URL" SortExpression = "SiteUrl" ></asp:BoundField>
</Columns>
</SharePoint:SPGridView>
<asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click" />
This is my usercontrol.ascx.cs code
protected void btnExport_Click(object sender, EventArgs e)
{
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
UserControl myControl = (UserControl)LoadControl("DomainUserWebPartUserControl.ascx");
domainGridview.RenderControl(hw);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=DataTable.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
This is the exception i am getting
Control 'ctl00_m_g_70a6af81_243a_45cf_a88e_3760d013ca12_ctl00_domainGridview' of type 'SPGridView' must be placed inside a form tag with runat=server.