Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

c# local variables help

  • 31-05-2007 10:38am
    #1
    Registered Users, Registered Users 2 Posts: 872 ✭✭✭


    Hi,

    In my code behind page i have

    private int propertyDescription = 1;

    which is defined just above the page load (under all the web controls)

    when someone checks a box i set propertyDescription = 2 in the event handler but the value isnt getting updated. Any ideas ?

    I know i should know how to do this !!

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Sounds like a state issue. Http is stateless so your site won't maintain values between the client and the server for you. You have to store them somewhere yourself. Put the value into ViewState or the Session to maintain it between the postbacks.

    Try
    protected void Page_Load(object sender, EventArgs e)
    {
       if(!IsPostBack)
       {
            ViewState["_propertyDescription"] = 1;
        }
    }
    // Your event handler goes here
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        ViewState["_propertyDescription"] = 2;
    }
    

    Then to access the propertyDescription value
    private void foo()
    {
        // Assumes you want it as an Int32
        Int32 propDescription = Convert.ToInt32(ViewState["_propertyDescription]); 
    }
    


Advertisement