首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

页面中保存变量的有关问题

2012-04-08 
页面中保存变量的问题方法一:privateintFlowID//窗体类变量privatevoidPage_Load(objectsender,System.Ev

页面中保存变量的问题
方法一:
private   int   FlowID;//窗体类变量
private   void   Page_Load(object   sender,   System.EventArgs   e)
{
FlowID   =   Request.QueryString[ "FlowID "]!=null?Int32.Parse//(Request.QueryString[ "FlowID "].ToString()):0;
}
方法二
public void   aa(){
ViewState[ "DocID "]   =   Convert.ToInt32(Request.QueryString[ "DocID "]);
}
请问哪个方式好?请说明下理由?谢谢

[解决办法]
通常情况下应该选用方法二,另外方法二可以改成属性,调用起来就方便了
public int aa
{
get
{
if (ViewState[ "DocID "] != null)
{
return Convert.ToInt32(ViewState[ "DocID "]);
}
else
{
return -1;
}
}
set
{
ViewState[ "DocID "] = value;
}
}

热点排行