Reputation: 220
I have a little issue here that i Can hope you guys can help with.
the problem is that I am have an auto-scroll function that scrolls the page between x intervals.
The thing is that there is also an auto refresh of the page(which is required due some data load) and the autoscroll stops because it's enabled by default.
I've tried to use the viewState but can't get it work.
Here is my ScrollFunction:
function Scroll(enable) {
if (Boolean(enable))
{
<%
setAutoScroll("true");
%>
}
else
{
<%
setAutoScroll("false");
%>
}
if (enable) {
var delay = document.getElementById('<%=ScrollDelayValue.ClientID%>').value * 1000;
var id = "";
$('body,html').animate({ scrollTop: $(document).height() }, delay);
//window.scrollBy(0, 50);
$('body,html').animate({ scrollTop: 0 }, delay);
id = setTimeout('Scroll(true);', 5000);
}
else {
<%DeleteCookie("autoscroll");%>
clearTimeout(id);
}
}
And on the Code-Behind i have this:
protected void Page_Load(object sender, EventArgs e)
{
if (ViewState["autoScrollEnabled"] != null)
{
scrollEnabled = ViewState["autoScrollEnabled"].ToString();
}
this.PreRender+=Default_PreRender;
}
private void Default_PreRender(object sender, EventArgs e)
{
ViewState.Clear();
ViewState.Add("autoScrollEnabled", scrollEnabled);
}
public string autoScrollEnabled()
{
return ViewState["autoScrollEnabled"].ToString();
}
public void setAutoScroll(string value)
{
if (ViewState["autoScrollEnabled"] != null)
{
ViewState["autoScrollEnabled"] = value;
}
}
the setAutoScroll is called from the client-Side. On the client-side I have an event that runs a function on document.ready:
<% if (autoScrollEnabled() == "true") { %>
Scroll(true);
<% } %>
<% if (autoScrollEnabled() == "false") { %>
Scroll(false);
Please advise.. :)
Upvotes: 0
Views: 235
Reputation: 68
If viewstate does not work, try to use Session instead.
Try to replace ViewState["autoScrollEnabled"]
as Session["autoScrollEnabled"]
Upvotes: 1