Doubt global variable?

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!
 
H

Hans Kesting

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
 
A

Aidy

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.
 

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,777
Messages
2,569,604
Members
45,208
Latest member
RandallLay

Latest Threads

Top