Solved

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

Posted on 2004-08-16
1
679 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 500 total points
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now