Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-08-16
1
Medium Priority
?
693 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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

721 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