shouldn't the DIV remember this?

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
 
N

Nathan Sokalski

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.
 
G

Guest

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')" />
 
N

Nathan Sokalski

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top