c# - how change page class parameter on post back -


i have asp.net page parameter named numberofselect , how can change parameter on postback ? want increase number of selected items when user click on button. after postback has 0 value!

    public partial class fetchondemand : system.web.ui.page {     int numberofselect=0;     protected void page_load(object sender, eventargs e)     {         if (!ispostback)         {             numberofselect = 20;          }         sqlconnection con = new sqlconnection("");         string strsql = "select top " + numberofselect + " * comment_table";         sqldataadapter dap = new sqldataadapter(strsql, con);         datatable dt = new datatable();         dap.fill(dt);         tblorders.datasource = dt;         tblorders.databind();     }     protected void hiddenbutton_click(object sender, eventargs e)     {         numberofselect = numberofselect + 10;       } } 

each request page, whether or not it's post-back, new request, means fetchondemand class reinstantiated on every request, resetting private field 0. should store value in viewstate manually or use <asp:hiddenfield /> control store value.

here's viewstate approach. instead of using private field, set property can read , write viewstate:

protected int numberofselect {       {       return (int)viewstate["numberofselect"];    }    set    {       viewstate["numberofselect"] = value;    } } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -