Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trap pre-Postback event to save values in session object.

Posted on 2004-08-16
1
Medium Priority
?
695 Views
Last Modified: 2008-02-26
Hi,

I have a number of values (including datasest) that I need to store in the session object.  One of these is real-time data that is constantly being streamed to my app.  

Is there a way of writing a generic trap-all-postbacks so that I can then update my session object BEFORE the actual post back.  ie If the user does ANYTHING that will cause a postback I want to have already updated my Session with all the required values so that I can repopulate them in the Page_load event.

Thanks.

James.
0
Comment
Question by:JAMES
1 Comment
 
LVL 8

Accepted Solution

by:
shovavnik earned 2000 total points
ID: 11808686
Actually, this is very simple!

You just need to understand the order of operations.

Any time you do a postback, what *really* happens is that the page is loaded first as if there was NO postback, and only then throws the postback events.

The postback events are thrown AFTER the Page_Load event is thrown.

So, if you want to populate your data before postback, you don't have to do anything special.  Just make sure you populate it in your Page_Load event handler or before.

If you want to add specific handling to check if the page is being called as a result of a postback event, use the boolean Page.IsPostBack property.

So, in your Page_Load() method:

public void Page_Load() {
  DataSet dsStreaming = CreateRealTimeStreamingDataSource();
  DataSet dsSession = null;
  if( IsPostBack ) dsSession = (DataSet) Session[ "SESSION_DATASET" ];
  if( dsSession != null ) {
    dsSession.Merge( dsStreaming ); // look up the dataset merge method in msdn.  There are several different types of merge, and you'll have to choose the one that best suits your needs.
    Session[ "SESSION_DATASET" ] = dsSession;
  }  
  MyDataGrid.DataSource = dsSession;
  MyDataGrid.DataBind();
}

Basically, you're loading two different datasets and then merging their data.  If you don't want to merge the datasets, then you don't need the session dataset as the streaming real time dataset always has the newest data.  That's the dataset you'll want to open update too.

The only thing you need to watch out for, is that in your event handlers you'll need to update data based on data keys and you'll need to check that the data still exists.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question