类变量由于回发而丢失 [英] Class variable losing because of Postback

查看:80
本文介绍了类变量由于回发而丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class A
{
    /// some variables
    bool isCorrect;
    .
    .
    .
    public Button1_click()
    {
        if(some_condition)
        {
        isCorrect=true;
        }
    }
    public Button2_click()
    {
        if(isCorrect)
        {
        ...some action
        }
    }
}


Button2_click在1之后被调用,由于回传值被重置.
如何避免这种情况?而且 Session/ViewState 也不能使用.
有任何建议吗?


Button2_click is call after 1, due to postback the value gets reset.
How this can be avoided? Also the Session/ViewState can''t be used.
Any suggestion?

推荐答案

您并没有分享太多的信息,可能导致会话丢失的方法是创建变量"static".

附注:您需要查看您是否要这么做.
You have not shared a lot just a scneario, possible way leaving session out is making the variable ''static''.

P.S.: You need to see if that is what you are after or not.




如果您需要保持此变量处于活动状态,那么Seession/ViewState/Cookies可能会为您提供帮助.或者您可以序列化此对象并将其存储在隐藏字段中.

希望这些信息对您有帮助

谢谢
-Amit Gajjar
Hi,

If you need to keep this variable live then Seession/ViewState/Cookies may help you. or you can serialize this object and store it in hidden field.

hope this information helps you

Thanks
-Amit Gajjar


这篇关于类变量由于回发而丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆