I am trying to load a script (that remembers the clicked nodes for a xsltlistview in a jquery cookie) on every postback.
The events when i postback should be: 1. save clicked nodes in cookie 2. postback 3. retrieve clicked nodes from cookie.
I call them like this:
_spBodyOnLoadFunctionNames.push("RememberClickedState");
_spBodyOnLoadFunctionNames.push("RestoreClickedState");
When I do this, the method RememberClickedState() doesnt work - my nodes appear all expanded, which means he did not store the correct values in the cookie.
I assume this happens because on postback, the controls are all rendered, the nodes are then again expanded, and only at the end of the process, the scripts are executed, at which point method RememberClickedState() does not see the correct nodes anymore.
This works when I test with a click event :
<a href="javascript:RememberClickedState()">Test here</a>
however I need this for every control that posts back, not just one anchor tag.
If it helps, this is the .js script:
<script type="text/javascript">
var items = '';
function RememberClickedState() {
$('.ms-listviewtable tbody[id^="tbod"]').each(function(){
tid = $(this).attr('id');
tvisible = ($(this).attr('style') == undefined || $(this).attr('style').indexOf('display: none;') == -1);
//tvisible = $(this).is(':visible');
//alert($(this).attr('style'));
items += tid+':'+tvisible+','
})
$.cookie("itemListState", items);
alert(items);
}
function RestoreClickedState() {
string = $.cookie("itemListState")
var string = items;
var cookies = string.split(',');
$.each(cookies, function(i, val){
val = val.split(':');
show = (val[1] == 'true' ? true:false);
item = $('.ms-listviewtable').find(/*'#'+*/val[0]);
show ? item.show() : item.hide();
})
}
_spBodyOnLoadFunctionNames.push("RememberClickedState");
_spBodyOnLoadFunctionNames.push("RestoreClickedState");
</script>
Any ideas?