Cached ObjectDataSource not firing Select Event even Cache Dependecy Removed
Posted
by John Polvora
on Stack Overflow
See other posts from Stack Overflow
or by John Polvora
Published on 2010-06-07T23:01:44Z
Indexed on
2010/06/08
1:52 UTC
Read the original article
Hit count: 283
cache
|objectdatasource
I have the following scenario.
A Page with a DetailsView binded to an ObjectDatasource with cache-enabled. The SelectMethod is assigned at Page_Load event, depending on my User Level Logic.
After assigned the selectMethod and Parameters for the ODS, if Cache not exists, then ODS will be cached the first time. The next time, the cache will be applied to the ODS and the select event don't need to be fired since the dataresult is cached.
The problem is, the ODS Cache works fine, but I have a Refresh button to clear the cache and rebind the DetailsView.
Am I doing correctly ? Below is my code.
<asp:DetailsView ID="DetailsView1"
runat="server"
DataSourceID="ObjectDataSource_Summary"
EnableModelValidation="True"
EnableViewState="False"
ForeColor="#333333" GridLines="None">
</asp:DetailsView>
<asp:ObjectDataSource ID="ObjectDataSource_Summary"
runat="server"
SelectMethod=""
TypeName="BL.BusinessLogic"
EnableCaching="true">
<SelectParameters>
<asp:Parameter Name="idCompany" Type="String" />
<SelectParameters>
</asp:ObjectDataSource>
<asp:ImageButton ID="ImageButton_Refresh" runat="server" OnClick="RefreshClick" ImageUrl="~/img/refresh.png" />
And here is the code behind
public partial class Index : Page
{
protected void Page_Load(object sender, EventArgs e)
{
ObjectDataSource_Summary.SelectMethod = "";
ObjectDataSource_Summary.SelectParameters[0].DefaultValue = "";
switch (this._loginData.UserLevel) //this is a struct I use for control permissions e pages behaviour
{
case OperNivel.SysAdmin:
case OperNivel.SysOperator:
{
ObjectDataSource_Summary.SelectMethod = "SystemSummary";
ObjectDataSource_Summary.SelectParameters[0].DefaultValue = "0";
break;
}
case OperNivel.CompanyAdmin:
case OperNivel.CompanyOperator:
{
ObjectDataSource_Summary.SelectMethod = "CompanySummary";
ObjectDataSource_Summary.SelectParameters[0].DefaultValue = this._loginData.UserLevel.ToString();
break;
}
default: break;
}
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
if (Cache[ObjectDataSource_Summary.CacheKeyDependency] == null)
{
this._loginData.LoginDatetime = DateTime.Now;
Session["loginData"] = _loginData;
Cache[ObjectDataSource_Summary.CacheKeyDependency] = _loginData;
DetailsView1.DataBind();
}
}
protected void RefreshClick(object sender, ImageClickEventArgs e)
{
Cache.Remove(ObjectDataSource_Summary.CacheKeyDependency);
}
}
Can anyone help me? The Select() Event of the ObjectDasource is not firing even I Remove the CacheKey Dependency
© Stack Overflow or respective owner