Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
class A
{
    /// some variables
    bool isCorrect;
    .
    .
    .
    public Button1_click()
    {
        if(some_condition)
        {
        isCorrect=true;
        }
    }
    public Button2_click()
    {
        if(isCorrect)
        {
        ...some action
        }
    }
}

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?
Posted
Updated 8-Aug-12 1:45am
v2
Comments
Prabhakaran Soundarapandian 8-Aug-12 8:21am    
can you explain your scenario better with the code you have tried..

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.
 
Share this answer
 
Comments
Hardik Turakhia 8-Aug-12 7:57am    
@prasad: it can't be static as the same class would be running in multiple instance and the field can't have same value for all instance
Timberbird 8-Aug-12 8:31am    
Static "sessionID - isCorrect" dictionary? Application state? Cache object?
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
 
Share this answer
 
Comments
Hardik Turakhia 8-Aug-12 8:09am    
@Amitgajjar : the value is critical and can't be allow to be played by users
AmitGajjar 8-Aug-12 8:38am    
then encrypt and store in the hidden field. or you can store session variables in sql server.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900