Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. HIddenfield value lost on postback - why?

HIddenfield value lost on postback - why?

Scheduled Pinned Locked Moved ASP.NET
javascriptsysadmintoolsquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AndyASPVB
    wrote on last edited by
    #1

    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

    R N 3 Replies Last reply
    0
    • A AndyASPVB

      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

      R Offline
      R Offline
      R Giskard Reventlov
      wrote on last edited by
      #2

      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

      N A 2 Replies Last reply
      0
      • A AndyASPVB

        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

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • R R Giskard Reventlov

          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

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          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

          R 1 Reply Last reply
          0
          • A AndyASPVB

            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

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • R R Giskard Reventlov

              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

              A Offline
              A Offline
              AndyASPVB
              wrote on last edited by
              #6

              maintainscrollposition does not work on asp:panels - I checked that too :-)

              1 Reply Last reply
              0
              • N Not Active

                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

                R Offline
                R Offline
                R Giskard Reventlov
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups