Click here to Skip to main content
12,403,948 members (65,354 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET C#4.0
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 8-Aug-12 1:43am
Updated 8-Aug-12 1:45am
v2
Comments
   
can you explain your scenario better with the code you have tried..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
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?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 8 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100