Solved

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

Posted on 2004-08-16
1
688 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
shovavnik earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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