【发布时间】:2016-09-29 15:23:58
【问题描述】:
我正在使用 C# 和 JQuery 数据表构建报告仪表板。该页面上的一份报告包含一个带有下拉列表的更新面板。当用户更改选择时,数据会根据 ddl 选择刷新。在每个块内还有一个链接,可以进行服务器端调用以将数据导出到 Excel。问题是,在我单击 Excel 导出链接后,下拉列表会失去任何功能,其他 Excel 下载链接也是如此。
这是我的代码:
<div id="dTopProducts" class="dashboardDiv" style="height:400px; width:485px; margin-top: 15px; margin-bottom:15px; margin-right: 15px;" runat="server">
<asp:UpdatePanel ID="upProducts" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProductsSector" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<div style="float: left;">
<h2>Top Products </h2>
</div>
<div style="float: left; ">
<asp:DropDownList
ID="ddlProductsSector"
AutoPostBack="true"
EnableViewState="true"
OnSelectedIndexChanged="ddlProductsSector_SelectedIndexChanged"
runat="server" />
</div>
<asp:UpdateProgress ID="prgProducts" AssociatedUpdatePanelID="upProducts" runat="server">
<ProgressTemplate>
<epriLoader:Loader runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:ListView
ID="lvTopProducts"
runat="server">
<ItemTemplate>
<tr style="padding-top: 5px; padding-bottom: 5px;">
<td style="padding-left: 0px;"><%# Eval("productId") %></td>
<td><%# Eval("productDesc") %></td>
<td style="text-align: right;"><%# Eval("quantity") %></td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<div style="float: left; padding-top: 25px;">
There are no product records found for the criteria provided
</div>
</EmptyDataTemplate>
<LayoutTemplate>
<table id="tblTopProducts" style="width: 100%">
<thead>
<tr style="padding-bottom: 10px; border: none;">
<th style="text-align: left; border: none; padding-left: 0px;">ID</th>
<th style="text-align: left; border: none; padding-left: 0px;">Name</th>
<th style="text-align: right; border: none;">Quantity</th>
</tr>
</thead>
<tfoot>
<tr>
<td style="border: none;"></td>
<td style="border: none;"></td>
<td style="border: none;"></td>
</tr>
</tfoot>
<tbody runat="server">
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
<%--Link that calls full export from funding page--%>
<a id="aTopProducts" class="invoicesLink" title="Click here to download full report" onserverclick="ExportTopProductsToExcel" runat="server">Download full Report</a>
</div>
这是 jQuery:
function bindTopProductsTable() {
var topProductsTable = $('#tblTopProducts').dataTable(
{
"scrollY": "225px",
"scrollCollapse": true,
"bSort": true,
"order": [[2, "desc"]],
"paging": false,
dom: '<"toolbar">rt<"floatRight"B><"clear">',
buttons: {
buttons: [
{ extend: 'excel', text: 'Export to Excel', exportOption: { page: 'current' }, footer: true, className: 'productsExportButton' }
]
}
});
};
此代码用于处理更新面板:
$(function () {
bindTopProductsTable(); // bind data table on first page load
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindTopProductsTable); // bind data table on every UpdatePanel refresh
});
我得到的错误是:
无法获取未定义或空引用的属性“样式”。
这是来自 IE JS 调试器的完整错误:
j.find("thead, tfoot").remove();j.append(h(a.nTHead).clone()).append(h(a.nTFoot).clone());j.find("tfoot th, tfoot td").css("width","");n=qa(a,j.find("thead")[0]);for(m=0;m<i.length;m++)o=c[i[m]],n[m].style.width=null!==o.sWidthOrig&&""!==o.sWidthOrig?x(o.sWidthOrig):"",o.sWidthOrig&&f&&h(n[m]).append(h("<div/>").css({width:o.sWidthOrig,margin:0,padding:0,border:0,height:1}));if(a.aoData.length)for(m=0;m<i.length;m++)t=i[m],o=c[t],h(Gb(a,t)).clone(!1).append(o.sContentPadding).appendTo(r);h("[name]",
毫不奇怪,这在 Chrome 中运行良好,在 IE 中崩溃了。
【问题讨论】:
-
如果删除模板中的样式属性会怎样?如果可行,也许您可以使用类(css),这是一种更好的方法:)。如果这些再次让 IE 失控,也许 dataTables 中有一个 oncompleted 事件可以连接你并让你应用所需的 CSS
-
您可以尝试从更新面板中删除
Triggers部分。由于ChildrenAsTriggers默认为true,ddlProductsSector已经是一个异步回发触发器。 -
您也可以使用
add_pageLoaded代替add_endRequest来设置bindTopProductsTable事件处理程序。每次刷新 UpdatePanel 时都会执行 -
触发器已删除,但不起作用。尝试添加到更新面板,但这也不起作用。我没有提到这是在 Sharepoint webpart 中,我认为在初始提交后有一些东西会影响页面。
-
想通了,我的答案在这里:stackoverflow.com/questions/7749393/…
标签: javascript c# jquery asp.net