Doubt global variable?

Discussion in 'ASP .Net' started by Paulo, Aug 31, 2007.

  1. Paulo

    Paulo Guest

    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!
    Paulo, Aug 31, 2007
    #1
    1. Advertising

  2. Paulo

    Paulo Guest

    Im using VS 2005 C# asp.net 2.0
    Paulo, Aug 31, 2007
    #2
    1. Advertising

  3. Paulo

    Hans Kesting Guest

    > 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
    Hans Kesting, Aug 31, 2007
    #3
  4. Paulo

    Aidy Guest

    > 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.
    Aidy, Aug 31, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bryan Parkoff
    Replies:
    2
    Views:
    6,471
  2. Bob Nelson

    doubt about doubt

    Bob Nelson, Jul 28, 2006, in forum: C Programming
    Replies:
    11
    Views:
    594
  3. Replies:
    0
    Views:
    536
  4. Peter Otten
    Replies:
    2
    Views:
    102
    Cousin Stanley
    Aug 10, 2013
  5. Terry Reedy
    Replies:
    0
    Views:
    106
    Terry Reedy
    Aug 10, 2013
Loading...

Share This Page