Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 ASP:NET
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
Edited 8-Aug-12 1:45am
v2
Comments
Prabhakaran Soundarapandian at 8-Aug-12 8:21am
   
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 at 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 at 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 at 8-Aug-12 8:09am
   
@Amitgajjar : the value is critical and can't be allow to be played by users
@amitgajjar at 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
0 Sergey Alexandrovich Kryukov 403
1 OriginalGriff 354
2 George Jonsson 202
3 Shemeemsha RA 148
4 Animesh Datta 130
0 OriginalGriff 6,189
1 Sergey Alexandrovich Kryukov 5,666
2 CPallini 4,810
3 George Jonsson 3,429
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 8 Aug 2012
Copyright © CodeProject, 1999-2014
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