Export HTML table to MS Excel Format Using jQuery
<p>I'm trying to follow this <a href="http://jsfiddle.net/jquerybyexample/xhYcD/" rel="nofollow">example</a>. To export an HTML table to MS Excel format using jQuery.</p>

<p>Here's my .aspx:</p>

<pre><code>&lt;head runat="server"&gt;
    &lt;title&gt;&lt;/title&gt;
    &lt;script src="Scripts/jQuery.1.8.3.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="Scripts/JScript2.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div&gt;
        &lt;asp:Table ID="tbl" runat="server"&gt;
        &lt;/asp:Table&gt;
        &lt;input type="button" id="btnExport" value=" Export Table data into Excel " /&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
</code></pre>

<p>The .js (JScript2.js):</p>

<pre><code>$("#btnExport").click(function (e) {
    window.open('data:application/vnd.ms-excel,' + $('#tbl').html());
    e.preventDefault();
});
</code></pre>

<p>... And the codebehind:</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class JQuery_Export_To_Excel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TableRow tr = new TableRow();
        TableCell tc = new TableCell();

        tc.Text = "AAA";
        tr.Cells.Add(tc);

        tc = new TableCell();
        tc.Text = "BBB";
        tr.Cells.Add(tc);

        tbl.Rows.Add(tr);    
    }
}
</code></pre>

<p>Generated page source:</p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;&lt;title&gt;

&lt;/title&gt;
    &lt;script src="Scripts/jQuery.1.8.3.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="Scripts/JScript2.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form method="post" action="JQuery_Export_To_Excel.aspx" id="form1"&gt;
&lt;div class="aspNetHidden"&gt;
&lt;input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2NTA0OTEwODdkZKr9kRtjn1C5sAo2woCwfF/8uHOVcyNi1bu4OtVBNKlS" /&gt;
&lt;/div&gt;

&lt;div class="aspNetHidden"&gt;

    &lt;input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAIdFUHUqRwMmhFieKB52uC8avDSflAS9b8PVcR1BxTTBqeDRyg6lH5NKPWh6Jt5ee2zX+bYNkguHBdZjCzKvoJa" /&gt;
&lt;/div&gt;
    &lt;div&gt;
        &lt;table id="tbl"&gt;
    &lt;tr&gt;
        &lt;td&gt;AAA&lt;/td&gt;&lt;td&gt;BBB&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;
        &lt;input name="btnExport" type="button" id="btnExport" value=" Export Table data into Excel " /&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I don't know what I'm doing wrong, but when I click <em>btnExport</em>, nothing happens. How can I fix this problem?</p>
