禁用 asp:Repeater 的 ViewState 会增加加载时间吗?
我有一个 asp:Repeater,一旦单击按钮,数据就会绑定到项目集合。标准票价。但是,如果我DISABLE转发器的ViewState,则单击按钮后加载转发器所需的时间会大大延长。这显然与我想要达到的效果相反。我所说的戏剧性是指启用 ViewState 时约 10 秒,禁用 ViewState 时约 35 秒。
我不知所措...
注意:在按钮单击的事件处理程序中,我还缓存了数据源。无论是否启用/禁用 ViewState,我都会执行此操作。使用 ViewState 时是否有可能忽略我的缓存?
这是相关代码:
<asp:repeater id="niinMatchesTable" runat="server" enableviewstate="false">
<headertemplate>
<table id="niinMatches" class="listing alternate">
<tr>
<th>QTY.</th>
<th><asp:linkbutton runat="server" onclick="sortResultsTable" commandargument="niin-niin" text="NIIN" /></th>
<th><asp:linkbutton runat="server" onclick="sortResultsTable" commandargument="niin-partnumber" text="PART #" /></th>
<th>Cases</th>
</tr>
</headertemplate>
<itemtemplate>
<tr class="odd">
<td><asp:label runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Quantity") %>' /></td>
<td><asp:label runat="server" text='<%# DataBinder.Eval(Container.DataItem, "NIIN") %>' /></td>
<td><asp:label runat="server" text='<%# DataBinder.Eval(Container.DataItem, "PartNumber") %>' /></td>
<td><asp:label runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Cases") %>' /></td>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:repeater>
protected void uploadClick(object sender, EventArgs e)
{
if (fileUploader.HasFile)
{
fileUploader.SaveAs(Server.MapPath("~/temp/inventory.xls"));
var niinMatches = getNiinMatches(); // Populates object by parsing spreadsheet
var absExp = System.Web.Caching.Cache.NoAbsoluteExpiration;
var slidingExp = TimeSpan.FromMinutes(10);
Cache.Insert("_niinMatches", niinMatches, null, absExp, slidingExp);
niinMatchesTable.DataSource = niinMatches;
niinMatchesTable.DataBind();
}
}
I have an asp:Repeater that is data bound to a collection of items once a button is clicked. Standard fare. However, if I DISABLE ViewState for the repeater, the time it takes to load the repeater after clicking the button takes dramatically longer. This is obviously the opposite of the effect I'm trying to achieve. By dramatic I mean ~10sec with ViewState enabled, and ~35sec with ViewState disabled.
I'm at a loss...
NOTE: In the event handler for the button click, I am also caching the data source. I am doing this regardless of whether I enable/disable ViewState. Is it possible that my caching is being ignored when ViewState is being used?
Here's the relevant code:
<asp:repeater id="niinMatchesTable" runat="server" enableviewstate="false">
<headertemplate>
<table id="niinMatches" class="listing alternate">
<tr>
<th>QTY.</th>
<th><asp:linkbutton runat="server" onclick="sortResultsTable" commandargument="niin-niin" text="NIIN" /></th>
<th><asp:linkbutton runat="server" onclick="sortResultsTable" commandargument="niin-partnumber" text="PART #" /></th>
<th>Cases</th>
</tr>
</headertemplate>
<itemtemplate>
<tr class="odd">
<td><asp:label runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Quantity") %>' /></td>
<td><asp:label runat="server" text='<%# DataBinder.Eval(Container.DataItem, "NIIN") %>' /></td>
<td><asp:label runat="server" text='<%# DataBinder.Eval(Container.DataItem, "PartNumber") %>' /></td>
<td><asp:label runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Cases") %>' /></td>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:repeater>
protected void uploadClick(object sender, EventArgs e)
{
if (fileUploader.HasFile)
{
fileUploader.SaveAs(Server.MapPath("~/temp/inventory.xls"));
var niinMatches = getNiinMatches(); // Populates object by parsing spreadsheet
var absExp = System.Web.Caching.Cache.NoAbsoluteExpiration;
var slidingExp = TimeSpan.FromMinutes(10);
Cache.Insert("_niinMatches", niinMatches, null, absExp, slidingExp);
niinMatchesTable.DataSource = niinMatches;
niinMatchesTable.DataBind();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在得出结论之前,我会获取 Firefox 的 Firebug 插件并检查什么需要这么长时间。但我没有看到按钮单击时缓存有任何真正的收益,因为每次单击按钮时缓存都会更新......除非有另一种方法将 gridview 绑定到每次回发时的缓存数据集。
Before jumping to conclusions i would get Firebug addon for firefox and check what takes so long. But I don't see any real gain of caching on button click, since each time the button is clicked cache will be updated... Unless there's another method that binds gridview to the cached dataset on each postback.