ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Download specific controls to word document in ASP.Net<p>Hi <a class="username" rel="saikumar">saikumar</a>,</p> <p>To export specific controls you need to place the controls that you want to export inside a div or panel. Then export the panel to control instead of complete page.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;div&gt; &lt;asp:Label ID=&#34;Label1&#34; Text=&#34;Test Label&#34; runat=&#34;server&#34; /&gt; &lt;asp:TextBox runat=&#34;server&#34; Text=&#34;Test&#34; /&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:Panel runat=&#34;server&#34; ID=&#34;pnlExport&#34;&gt; &lt;table border=&#34;1&#34; cellpadding=&#34;0&#34; cellspacing=&#34;0&#34;&gt; &lt;tr&gt; &lt;td&gt; Name &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtName&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Age &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtAge&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/asp:Panel&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:Button Text=&#34;Export&#34; runat=&#34;server&#34; OnClick=&#34;Export&#34; /&gt; &lt;/div&gt;</pre> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">protected void Export(object sender, EventArgs e) { Response.Clear(); Response.Buffer = true; Response.ContentType = &#34;application/msword&#34;; System.IO.StringWriter stringWriter = new System.IO.StringWriter(); HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter); pnlExport.RenderControl(htmlTextWriter); Response.Write(stringWriter.ToString()); Response.End(); } public override void VerifyRenderingInServerForm(Control control) { /* Verifies that the control is rendered */ }</pre> <p><strong><span style="text-decoration: underline;">VB.Net</span></strong></p> <pre class="brush: vb">Protected Sub Export(ByVal sender As Object, ByVal e As EventArgs) Response.Clear() Response.Buffer = True Response.ContentType = &#34;application/msword&#34; Dim stringWriter As System.IO.StringWriter = New System.IO.StringWriter() Dim htmlTextWriter As HtmlTextWriter = New HtmlTextWriter(stringWriter) pnlExport.RenderControl(htmlTextWriter) Response.Write(stringWriter.ToString()) Response.End() End Sub Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) &#39; Verifies that the control is rendered End Sub</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><span style="text-decoration: underline;">Page</span></p> <p><strong><img src="https://i.imgur.com/vNev0lT.jpg" alt="" width="242" height="214" /></strong></p> <p><span style="text-decoration: underline;">After export to word document</span></p> <p><strong><img src="https://i.imgur.com/s2BWdxd.jpg" alt="" width="305" height="262" /></strong></p>https://www.aspforums.net:443/Threads/656133/Download-specific-controls-to-word-document-in-ASPNet/https://www.aspforums.net:443/Threads/656133/Download-specific-controls-to-word-document-in-ASPNet/Tue, 10 Apr 2018 04:05:03 GMT