Doubt global variable?

  • Thread starter Thread starter Paulo
  • Start date Start date
P

Paulo

Hi, I have a first button_click wich generates/fill a DataSet, etc, etc...

and on a second button click I need to access the DataSet generated by the
first button to manipulate some rows, etc, but how can I do that?

Something like declaring a global variable? Can you help me ?

Thanks!
 
Hi, I have a first button_click wich generates/fill a DataSet, etc,
etc...

and on a second button click I need to access the DataSet generated by
the first button to manipulate some rows, etc, but how can I do that?

Something like declaring a global variable? Can you help me ?

Thanks!

Don't use a global variable (static variable, singleton) for this, as this
will mean
that all your users use the same dataset.
Use the Session to store something user-specific.

page1.aspx:
Session["MyDataset"] = GenerateDataset();

page2.aspx:
DataSet myDataset = (DataSet)Session["MyDataset"];



Hans Kestin
 
and on a second button click I need to access the DataSet generated by the
first button to manipulate some rows, etc, but how can I do that?

One way is to store it in the Session;

Session["MyData"] = myDataSet;

then to read it;

myDataSet = (DataSet) Session["MyData"];

I'd want to be careful about holding large amounts of data in the Session
needlessly though so ensure it is removed when no longer needed. The
alternative is to use the ViewState which will work if you are working on
the same page. That will store it in the FORM, but again note that if the
dataset is large it will mean posting a large form when the user submit the
page.
 
Back
Top