开发者

loading data into session only once

I have a master page where I'm loading some data into the session.

I put the lines of code that call my queries in the Page_Init event of the master page, inside an if statement

if (!Page.IsPostBack){ load data from queries into the session }

Is this what I need for all the session data to be loaded only once per session. What about call backs? Do I also need to check to avoid a reload of session data on call backs? Any other condition I need to check to avoid unnecessary reloads of session data? I'm looking to run the queries inside the condition statement only once.

T开发者_JS百科hanks.


No. What you just posted won't guarantee that will be called once per session. In fact, every time your ASPX page is invoked with a GET command, the data will be loaded.

If you want data to be loaded just once by HTTP session (I am assuming by session you mean HTTP session) then try Session_OnStart event handler.


You can check to see if the session variable is null. If it is null then load the data. If it is not null then do nothing.

As Pablo Santa Cruz suggests, the best place to load the session variable is in the Sessio_OnStart event handler but a quick and dirty way is to simply check for the sessions existence in the Page_Init event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜