I have a website (ASP.NET webforms), and I use a jQuery plugin to build a tree on the client side. For this I build a string with StringBuilder, and then have my data like this:
dataForTree = "var data=" + sb.T开发者_如何学PythonoString() + ";";
Then I pass this to my tree by using RegisterClientScriptBlock, like this:
if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "allData"))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "allData", dataForTree, true);
}
And on my client I receive the data like this:
<script type="text/javascript">
$(function () {
$("#myTree").dynatree({
children: $(data)
});
});
Now I know the data is passed correctly, because I get the right treeview on load, and all is great. When I activate a node, I need to display some data about this node, so I make a postback to apply to the server, and I pass the data again. This works as well, everything is displayed great.
But then I leave this page be for a while, just a few minutes is enough, and activate a node again. And then there's the problem. My tree disappears. When I look at the code in Chrome debugger or in Firebug, I see that data variable is not there. Although, I repeat, I pass it to the client on every postback. Why this happens - I never know. Seriously, I've broken my head over it, I just can't see why it is as it is.
If you're using un UpdatePanel, remeber to check if Session is expired in the PreInit of the page:
protected override void OnPreInit(EventArgs e)
{
if (Session["User"]==null )
Response.Redirect("~/Login.aspx");
}
精彩评论