日期:2014-05-20  浏览次数:20426 次

页面中保存变量的问题
方法一:
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;
}
}