Rushikesh
Rushikesh

Reputation: 529

Session losing its state after javascript function call

We are using Sharepoint 2007 We initialising the session variable on page load We have one javascript function as mentioned below

function backclick()
{
 __doPostBack('btnCaseSearch', 'Click'); 
alert('Select the Search Criteria.');
}

but after calling this we are losing session value. If we remove __doPostBack('btnCaseSearch', 'Click'); then alert is displaying each time when page gets load but session is not losing its value. How to maintain session pls help or suggest some alternative to _doPostBack()

the sceneario is like this below javascript function

function backclick()
{
 __doPostBack('btnCaseSearch', 'Click'); 
alert(result not found.');
}

function check()
{
var btn ="<%=Session["search"]%>";
if(btn == "true")
{
do something
}
else
{
else part
}

Below server side code

Page_Load()
{
//initialise session variable
session["search"] = "true";
}
btnSearch_click()
{
 if(result not found)
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(),"page_index_script1", "backclick();", true);

}
}

so when backclick() javascript function gets called at that time session is losing its state but if backclick() doesn't get called then code works perferctly

Thanks

Upvotes: 1

Views: 1443

Answers (1)

m.edmondson
m.edmondson

Reputation: 30922

Something which jumped out at me:

We initialising the session variable on page load

Is this page load server-side?

Each time you _doPostBack will cause pageLoad to execute, so I believe this is where you're overwriting your session variable.

The only way the session will loose it's state is:

  • If it gets overwritten or removed (use a breakpoint to check you're not setting it twice!)
  • The browser is not surrendering the cookie on subsequent requests

Check both of these and if your problem isn't solved post what you found.

Upvotes: 3

Related Questions