0

I'm using two web controls. Web control A includes webcontrol B. When webcontrol A is called, it automatically calls webcontrolB. WebcontrolB passes a value to the method Modify() of webcontrolA. I would like to store an object, and I do it using viewstate:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            object o = Object;
            ViewState["o"] = o;

        }
    }

The problem is that when I return back to webcontrolA the object that I retrieve from ViewState is null. So the object is not stored when another webcontrol is executed. Ho can I store it?? I tried also Session but it gaves me the following error: "Error Message: Object reference not set to an instance of an object"

to retrieve the value from viewstate I used this:

public void Modify(int i)
{    
   object o = (object)ViewState["o"];  //result is null :(
}
Camilla
  • 949
  • 2
  • 14
  • 26

1 Answers1

0

ViewState is persisted when you stay on the same page, you do postback operations (click button on the same page)

If you have lost viewstate value => it's possible that you navigate arround your application

In the case of navigation you can use session variable

Session["o"] = o;
Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
  • So, I'm navigating through controls, but when I use Session it returns me this error: "Error Message: Object reference not set to an instance of an object" – Camilla Jan 31 '13 at 14:06