62,268
社区成员
发帖
与我相关
我的任务
分享
protected override void OnInit(EventArgs e)
{
String Key = "BrandID=" + BrandID.ToString(); //这里取得自己的自定义属性
String CacheName = "ControlCache_" + "ControlCacheTest_Test" + "_" + Key; //由ControlCache_用户控件命名空间_属性值合成 全成一个Cache关键字
//判断是否有Cache 有就读取
if (Cache[CacheName] != null)
{
String ControlCacheHtml = Context.Cache.Get(CacheName).ToString();
//PreInit->Init->InitComplete->PreLoad->Load->控件事件(如Click)->LoadComplete->PreRender->SaveStateComplete->Render->Unload
//这里怎么直接在Init输出Html内容,而不再执行后台的onload什么就直接输出
//???
}
else
{
//如果没有cache程序正常运行
base.OnInit(e);
}
}
protected override void Render(HtmlTextWriter writer)
{
String Key = "BrandID=" + BrandID.ToString(); //这里取得自己的自定义属性
String CacheName = "ControlCache_" + "ControlCacheTest_Test" + "_" + Key; //由ControlCache_用户控件命名空间_属性值合成 全成一个Cache关键字
//判断是否有Cache 没有添加
if (Cache[CacheName] == null)
{
//没有Cache进行添加到Cache
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);
//将内容插入Cache中,并指定过期时间为6000秒,每有访问继续延长
Context.Cache.Insert(CacheName, sb.ToString(), null, DateTime.Now.AddSeconds(6000), TimeSpan.FromSeconds(6000));
}
base.Render(writer);
}
protected override void Render(HtmlTextWriter writer)
{
String Key = "BrandID=" + BrandID.ToString(); //这里取得自己的自定义属性
String CacheName = "ControlCache_" + "ControlCacheTest_Test" + "_" + Key; //由ControlCache_用户控件命名空间_属性值合成 全成一个Cache关键字
//没有Cache进行添加到Cache
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(sw);
base.Render(hw);
//将内容插入Cache中,并指定过期时间为6000秒,每有访问继续延长
Context.Cache.Insert(CacheName, sb.ToString(), null, DateTime.Now.AddSeconds(6000), TimeSpan.Zero);
writer.Write(sb.ToString());
}