HIddenfield value lost on postback - why?
-
Hi I have a hiddenfield, which I want to save the scroll position of asp.panel scrollbar during postback, and when during postback this value is called back to set the scroll position. Using javascript I can grab the value from the scrollbar, and assign it to the hidden field, but when I post the page back the value has gone. Here is my code snippet: <script type="text/javascript" language="javascript"> function SetScroll(val) { alert(document.getElementById('div1').childNodes('ScrollPos').value); } function ScrollTo(what) { var test = what.split('/'); document.getElementById(test[0]).scrollTop = document.getElementById('div1').childNodes('ScrollPos').value; } </script> <div id="div1" class="Style"> <input type="hidden" id="ScrollPos" name="Pos" runat="server" enableviewstate="true"/> <asp:Panel ID="pnl1" runat="server" Enabled="true" Height="600px" ScrollBars="Vertical" Width="100%" onscroll="javascript:SetScroll(this);"> <br /> <div class="divTagBGColours"> </div> <br /> <asp:BulletedList ID="BulletedList2" runat="server"> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="H
-
Hi I have a hiddenfield, which I want to save the scroll position of asp.panel scrollbar during postback, and when during postback this value is called back to set the scroll position. Using javascript I can grab the value from the scrollbar, and assign it to the hidden field, but when I post the page back the value has gone. Here is my code snippet: <script type="text/javascript" language="javascript"> function SetScroll(val) { alert(document.getElementById('div1').childNodes('ScrollPos').value); } function ScrollTo(what) { var test = what.split('/'); document.getElementById(test[0]).scrollTop = document.getElementById('div1').childNodes('ScrollPos').value; } </script> <div id="div1" class="Style"> <input type="hidden" id="ScrollPos" name="Pos" runat="server" enableviewstate="true"/> <asp:Panel ID="pnl1" runat="server" Enabled="true" Height="600px" ScrollBars="Vertical" Width="100%" onscroll="javascript:SetScroll(this);"> <br /> <div class="divTagBGColours"> </div> <br /> <asp:BulletedList ID="BulletedList2" runat="server"> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="H
Does this help: Maintain Scroll Position on Postback[^]. Not checked it but it looks close to what you want. Took 1 second to Google that. :-)
Tychotics "The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!" Larry Niven
-
Hi I have a hiddenfield, which I want to save the scroll position of asp.panel scrollbar during postback, and when during postback this value is called back to set the scroll position. Using javascript I can grab the value from the scrollbar, and assign it to the hidden field, but when I post the page back the value has gone. Here is my code snippet: <script type="text/javascript" language="javascript"> function SetScroll(val) { alert(document.getElementById('div1').childNodes('ScrollPos').value); } function ScrollTo(what) { var test = what.split('/'); document.getElementById(test[0]).scrollTop = document.getElementById('div1').childNodes('ScrollPos').value; } </script> <div id="div1" class="Style"> <input type="hidden" id="ScrollPos" name="Pos" runat="server" enableviewstate="true"/> <asp:Panel ID="pnl1" runat="server" Enabled="true" Height="600px" ScrollBars="Vertical" Width="100%" onscroll="javascript:SetScroll(this);"> <br /> <div class="divTagBGColours"> </div> <br /> <asp:BulletedList ID="BulletedList2" runat="server"> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="H
First, format the code you post using the pre tags Second, Do not repost the same question, continue with the original thread. where everyone can see the previous responses and reply to gain context.
I know the language. I've read a book. - _Madmatt
modified on Friday, March 12, 2010 10:30 AM
-
Does this help: Maintain Scroll Position on Postback[^]. Not checked it but it looks close to what you want. Took 1 second to Google that. :-)
Tychotics "The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!" Larry Niven
That deals with maintaining the scroll position of the page, not an individual element within the page.
I know the language. I've read a book. - _Madmatt
-
Hi I have a hiddenfield, which I want to save the scroll position of asp.panel scrollbar during postback, and when during postback this value is called back to set the scroll position. Using javascript I can grab the value from the scrollbar, and assign it to the hidden field, but when I post the page back the value has gone. Here is my code snippet: <script type="text/javascript" language="javascript"> function SetScroll(val) { alert(document.getElementById('div1').childNodes('ScrollPos').value); } function ScrollTo(what) { var test = what.split('/'); document.getElementById(test[0]).scrollTop = document.getElementById('div1').childNodes('ScrollPos').value; } </script> <div id="div1" class="Style"> <input type="hidden" id="ScrollPos" name="Pos" runat="server" enableviewstate="true"/> <asp:Panel ID="pnl1" runat="server" Enabled="true" Height="600px" ScrollBars="Vertical" Width="100%" onscroll="javascript:SetScroll(this);"> <br /> <div class="divTagBGColours"> </div> <br /> <asp:BulletedList ID="BulletedList2" runat="server"> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="Hello" Value="blah" /> <asp:ListItem Text="H
It seems you are just throwing things together at this point with very little understanding of ASP.NET and hoping that it works. I would suggest you step back, take some time to understand ASP.NET and in particular maintaining state for controls or values within a page, then come back to the problem at hand after you have the knowledge.
I know the language. I've read a book. - _Madmatt
-
Does this help: Maintain Scroll Position on Postback[^]. Not checked it but it looks close to what you want. Took 1 second to Google that. :-)
Tychotics "The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!" Larry Niven
-
That deals with maintaining the scroll position of the page, not an individual element within the page.
I know the language. I've read a book. - _Madmatt
Yup, you're right: just saw scroll and maintain.
Tychotics "The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!" Larry Niven