shouldn't the DIV remember this?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,
i have a div on my page where i set the ScrollLeft value. when i do a
postback the div is set back to 0. i've made the DIV runat server and enabled
viewstate. what would i have to do to make this work?

thanks,
rodchar
 
Are you setting ScrollLeft using JavaScript or during a postback? If you are
setting it using JavaScript it will not be remembered because the JavaScript
will not modify the ViewState. It may also be helpful if you showed us your
code.
 
yes i am setting value using javascript that's in the head section. so do i
have any options this way?

<script language="javascript" type="text/javascript">
// <!CDATA[
function scrollDiv(direction){
y=document.getElementById("OnlyDIV")
y.scrollLeft=(direction=="left")?y.scrollLeft-75:y.scrollLeft+75
c.value=y.scrollLeft;
}

<html>
....
<input id="BtnLeft" style="width: 46px; height: 24px"
type="button" value="Left"
onclick="scrollDiv('left')" />
 
There is no way to have ViewState remember values set using JavaScript, but
what you can do is create an <input type="hidden"> and set the value
property as part of the function. Then when you postback you can have
ASP.NET use that value when generating the returned page. This is usually
the best way to avoid losing values set by JavaScript. Good Luck!
--
Nathan Sokalski
(e-mail address removed)
http://www.nathansokalski.com/

rodchar said:
yes i am setting value using javascript that's in the head section. so do
i
have any options this way?

<script language="javascript" type="text/javascript">
// <!CDATA[
function scrollDiv(direction){
y=document.getElementById("OnlyDIV")
y.scrollLeft=(direction=="left")?y.scrollLeft-75:y.scrollLeft+75
c.value=y.scrollLeft;
}

<html>
...
<input id="BtnLeft" style="width: 46px; height: 24px"
type="button" value="Left"
onclick="scrollDiv('left')" />


Nathan Sokalski said:
Are you setting ScrollLeft using JavaScript or during a postback? If you
are
setting it using JavaScript it will not be remembered because the
JavaScript
will not modify the ViewState. It may also be helpful if you showed us
your
code.
 
thank you for the help.
rod.

Nathan Sokalski said:
There is no way to have ViewState remember values set using JavaScript, but
what you can do is create an <input type="hidden"> and set the value
property as part of the function. Then when you postback you can have
ASP.NET use that value when generating the returned page. This is usually
the best way to avoid losing values set by JavaScript. Good Luck!
--
Nathan Sokalski
(e-mail address removed)
http://www.nathansokalski.com/

rodchar said:
yes i am setting value using javascript that's in the head section. so do
i
have any options this way?

<script language="javascript" type="text/javascript">
// <!CDATA[
function scrollDiv(direction){
y=document.getElementById("OnlyDIV")
y.scrollLeft=(direction=="left")?y.scrollLeft-75:y.scrollLeft+75
c.value=y.scrollLeft;
}

<html>
...
<input id="BtnLeft" style="width: 46px; height: 24px"
type="button" value="Left"
onclick="scrollDiv('left')" />


Nathan Sokalski said:
Are you setting ScrollLeft using JavaScript or during a postback? If you
are
setting it using JavaScript it will not be remembered because the
JavaScript
will not modify the ViewState. It may also be helpful if you showed us
your
code.
--
Nathan Sokalski
(e-mail address removed)
http://www.nathansokalski.com/

hey all,
i have a div on my page where i set the ScrollLeft value. when i do a
postback the div is set back to 0. i've made the DIV runat server and
enabled
viewstate. what would i have to do to make this work?

thanks,
rodchar
 
Back
Top