can't use a viewstate variable on page init

Joined
May 11, 2007
Messages
1
Reaction score
0
I am trying to find a way of passing the number of dynamic controls I have created in the page init phase and be able to read it on post back so I can recreate the controls.
I tried session["myvariable"] = num as well but couldn't get that to work either




protected override void OnInit(EventArgs e)
{
base.OnInit(e);


if (!IsPostBack)
{



int x = 1;



this.NumberOfControls = 17; ........




protected int NumberOfControls
{
get { return (int)ViewState["NumControls"]; }
set { ViewState["NumControls"] = value; }

}

after postback
I want read the variable NumberOf Controls
but error says it is a null reference

protected void Button1_Click(object sender, EventArgs e)
{

int count = this.NumberOfControls;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top