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 all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

c# local variables help

Options
  • 31-05-2007 11:38am
    #1
    Registered Users 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 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