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. Postback and scroll position

Postback and scroll position

Scheduled Pinned Locked Moved ASP.NET
question
6 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.
  • D Offline
    D Offline
    devvvy
    wrote on last edited by
    #1

    Some of our users are complaining that everytime they submit something the page is positioned back to top of the page. How can I preserver scroll position on postbacks? Thanks in advance. Norman Fung

    M T 2 Replies Last reply
    0
    • D devvvy

      Some of our users are complaining that everytime they submit something the page is positioned back to top of the page. How can I preserver scroll position on postbacks? Thanks in advance. Norman Fung

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi Norman, In ASP.NET 2.0, you don't need to care about this issue as the ASP.NET 2.0 automatically does that for you, hopefully this feature will be supported in the release. Until then, you'll have to provide some code to do that with ASP.NET 1.x. The sample code is something like this:

      private void RegisterFocusScript(System.Web.UI.Control control)
      {
      string script = "<script language=\"javascript\">";
      script += "window.document.getElementById(\"" + control.ClientID + "\").focus();";
      script += "</script>";

      if(!this.IsStartupScriptRegistered("clientFocusScript"))
      	this.RegisterStartupScript("clientFocusScript", script);
      

      }

      You can call this method in a post back event's handler of a control like SelectedIndexChanged, TextChanged, Click....

      private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
      {
      RegisterFocusScript(DropDownList1);
      }

      D 1 Reply Last reply
      0
      • M minhpc_bk

        Hi Norman, In ASP.NET 2.0, you don't need to care about this issue as the ASP.NET 2.0 automatically does that for you, hopefully this feature will be supported in the release. Until then, you'll have to provide some code to do that with ASP.NET 1.x. The sample code is something like this:

        private void RegisterFocusScript(System.Web.UI.Control control)
        {
        string script = "<script language=\"javascript\">";
        script += "window.document.getElementById(\"" + control.ClientID + "\").focus();";
        script += "</script>";

        if(!this.IsStartupScriptRegistered("clientFocusScript"))
        	this.RegisterStartupScript("clientFocusScript", script);
        

        }

        You can call this method in a post back event's handler of a control like SelectedIndexChanged, TextChanged, Click....

        private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
        RegisterFocusScript(DropDownList1);
        }

        D Offline
        D Offline
        devvvy
        wrote on last edited by
        #3

        Thanks a bunch! Norman Norman Fung

        1 Reply Last reply
        0
        • D devvvy

          Some of our users are complaining that everytime they submit something the page is positioned back to top of the page. How can I preserver scroll position on postbacks? Thanks in advance. Norman Fung

          T Offline
          T Offline
          tonaxxl
          wrote on last edited by
          #4

          make the smartnavigation property of the Page to True

          M D 2 Replies Last reply
          0
          • T tonaxxl

            make the smartnavigation property of the Page to True

            M Offline
            M Offline
            minhpc_bk
            wrote on last edited by
            #5

            Good point, tonaxxl!

            1 Reply Last reply
            0
            • T tonaxxl

              make the smartnavigation property of the Page to True

              D Offline
              D Offline
              devvvy
              wrote on last edited by
              #6

              Hey thanks! Although I've already spent a day fixing it using Javascript (There're many such control on the mainpage which requires such correction), but, it's still nice to know. Norman Fung

              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