.net定义的变量,刷新页面后重用的方法?

来源:百度知道 编辑:UC知道 时间:2024/05/21 11:35:19
我定义了一个icount
public static int icount;
然后页面Load时:
if(icount==0)
{
if (!Page.IsPostBack)
{
icount++; Response.Write("<script>open('blog.aspx','_parent')</script>");
}
}

但是,页面刷新后,又变回0了,如何让页面刷新后会存为icount++时的值

这个好解决:
如果你是在当前页进行处理,你可以使用ViewState变量;
if(icount==0)
{
if (!Page.IsPostBack)
{
ViewState["icount"] = icount++;
Response.Write("<script>open('blog.aspx','_parent')</script>");
}
}

如果是该值需要使用到其他的页面就使用Session变量:

if(icount==0)
{
if (!Page.IsPostBack)
{
Session["icount"] = icount++;
Response.Write("<script>open('blog.aspx','_parent')</script>");
}
}

只能放到SESSION里面了

新建一个类文件,把icount写到新的类文件里。

用SESSION.

记着判断SESSION值是否为NULL.

把这个icount传值过去啊'blog.aspx?icount='+icount