当enable-caching为true时,为ObjectDatasource引发的选定事件 [英] Selected event not raised for ObjectDatasource when enable-caching is true

查看:165
本文介绍了当enable-caching为true时,为ObjectDatasource引发的选定事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Gridview控件使用ODS(ObjectDataSource)来获取数据。为了获得最佳的性能和效率,我关闭了Gridview的视图状态(即EnableViewstate =false)。

I've a Gridview control using an ODS(ObjectDataSource) to fetch data. For the best performance and efficiency, I've turned-off the view state of Gridview (i.e. EnableViewstate = "false".

关联的Objectdatasource,这消除了多达50-60%的性能优化,因为它消除了数据库往返程序。ODS缓存。

And I've also enabled caching in the associated Objectdatasource. This eliminates as much as 50-60% performance optimization because it eliminates the DB round-trip .. courtesy ODS Caching.

进入着名的ODS排序问题,但我设法发明一个棘手的解决方案,它的工作正常:

So, after this I got stuck into the famous "ODS sorting" issue but I managed to invent a tricky solution for it and its working fine:


使用具有EnableCaching = true的ObjectDataSource优化分页和排序

下一页,它也工作正常现在,我需要在Gridview的顶部显示Total records:X。以下方法:

Next pagination, it is also working fine. Now, I need to display "Total records: X" at the top of the Gridview. Well, I deployed the following method:

protected void ods_Selected(object sender, ObjectDataSourceStatusEventArgs e)
        {
            if(e.ReturnValue != null && e.ReturnValue.GetType() == typeof(int))
                base.setTotalLabel(lblTotal, e.ReturnValue);
        }

不要混淆 - base.setTotalLabel是我自己设置标签的方法文本与计数。这也工作正常,但问题是 -

Don't confuse - base.setTotalLabel is my own method to set the label text with the count. This is also working fine but the issue is that -


无论何时,ODS从
获取数据它的缓存不会触发
ODS_Selecting或ODS_Select事件。
它们只是旁路,因为它
从缓存获取数据。这是当I
无法刷新总记录
count!

Whenever, the ODS fetches data from its Cache it won't trigger the ODS_Selecting or ODS_Select events. They are simply "by-passed" because it takes data from cache. This is when I fail to refresh the Total records count!

我希望我解释了问题好,这是棘手的。我准备好做任何欺骗或肮脏的代码,因为我想维护ODS缓存,我不能回滚更改只是因为一些偶然的错误更新。

I hope I've explained my problem good, this is tricky. I'm ready to do any trick or dirty coding for this because I want to maintain the ODS-caching and I can't rollback changes just because of a few incidental "mis-updates".

Pls help!

推荐答案

这对我有用,我设置了CacheKeyDependency,值每当我想刷新。如果我要显式刷新,则传递& refresh = 1。

This worked for me I set the CacheKeyDependency and I explicitly set it to a new value whenever I want to refresh. I pass &refresh=1 in querystring if I want to explicitly refresh.

在.aspx -

In .aspx -

<asp:ObjectDataSource ID="odsOrg" runat="server" SelectMethod="SearchOrg" ... EnableCaching="true" CacheDuration="60" CacheKeyDependency="key1">

在代码后面 -

public const string argRefresh = "refresh=1";
public void CheckExpiredCacheKey(string ckey)
{
 if (Cache[ckey] == null) 
  Cache[ckey] = new object(); //Set Cache key which will b used to manually expire ODS cache     

if (!IsPostBack && Request.QueryString["refresh"] == "1")//check refresh flag
 {
    //Cache.Remove(ckey);//NOT NEEDED: use the following instead
    Cache[ckey] = new object();// Needed otherwise it'll call Grid-populate twice
 } 
}

这篇关于当enable-caching为true时,为ObjectDatasource引发的选定事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆