Solved

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

Posted on 2004-08-16
1
689 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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 …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

623 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