控件是动态加载的,对于常用的用户控件,本人想到了用cache来 优化速度,可是当把用loadcontrol 动态加载出来的控件保存到cache后,再拿出来添加到界面上,提示出错,代码如下 Control appcont = new Control();
string appid = jsobj["appid"].ToString();
object appobj = Maticsoft.Common.DataCache.GetCache(appid);
if (appobj!=null) appcont = (Control)appobj;
else {
////取应用路径
sqlstr = "select appaddr from app where appno='" + appid + "'";
try
{
SqlDataReader dr = DbHelperSQL.ExecuteReader(sqlstr);
if (dr.Read())
appcont = Page.LoadControl(dr["appaddr"].ToString());
dr.Close();
Maticsoft.Common.DataCache.SetCache(appid, appcont);//自己写得保存到cache的类,
使用 cache.insert
//Application[appid] = appcont; }
catch { return; } System.Type wxd_type;
wxd_type = appcont.GetType();
System.Reflection.PropertyInfo wxd_property;
JsonArray appattrjson = null;
if (appattrjsons != null)
{
appattrjson = appattrjsons[appid] as JsonArray;
}
if (appattrjson != null)
{
foreach (JsonObject attrjson in appattrjson)
{
wxd_property = wxd_type.GetProperty(attrjson["attrid"].ToString());
// typeof(wwxd_property)
wxd_property.SetValue(appcont, attrjson["attrvalue"].ToString(), null);
}
}
addcontrol.Controls.Add(appcont);/////刷新界面,加载cache里面的控件时出错,
首先提示updatepannel1不能注销,说先注销,然后加载的情况是不允许的(我有些控件有updatepannel)。
然后提示不能在init,load等状况 下修改控件集合。
}
string appid = jsobj["appid"].ToString();
object appobj = Maticsoft.Common.DataCache.GetCache(appid);
if (appobj!=null) appcont = (Control)appobj;
else {
////取应用路径
sqlstr = "select appaddr from app where appno='" + appid + "'";
try
{
SqlDataReader dr = DbHelperSQL.ExecuteReader(sqlstr);
if (dr.Read())
appcont = Page.LoadControl(dr["appaddr"].ToString());
dr.Close();
Maticsoft.Common.DataCache.SetCache(appid, appcont);//自己写得保存到cache的类,
使用 cache.insert
//Application[appid] = appcont; }
catch { return; } System.Type wxd_type;
wxd_type = appcont.GetType();
System.Reflection.PropertyInfo wxd_property;
JsonArray appattrjson = null;
if (appattrjsons != null)
{
appattrjson = appattrjsons[appid] as JsonArray;
}
if (appattrjson != null)
{
foreach (JsonObject attrjson in appattrjson)
{
wxd_property = wxd_type.GetProperty(attrjson["attrid"].ToString());
// typeof(wwxd_property)
wxd_property.SetValue(appcont, attrjson["attrvalue"].ToString(), null);
}
}
addcontrol.Controls.Add(appcont);/////刷新界面,加载cache里面的控件时出错,
首先提示updatepannel1不能注销,说先注销,然后加载的情况是不允许的(我有些控件有updatepannel)。
然后提示不能在init,load等状况 下修改控件集合。
}
ASP.NET分页最终解决之道:http://www.webdiyer.com
我可以先把控件加载出来,存起来,不同用户调用时候我再赋予 控件不同属性 那样子 不是更好吗?
那样子行吗?