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. Scroll control into view after postback

Scroll control into view after postback

Scheduled Pinned Locked Moved ASP.NET
questiontutorial
3 Posts 2 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.
  • L Offline
    L Offline
    lustuyck
    wrote on last edited by
    #1

    Hi, I use linkbuttons on my page, and use the click events to do some stuff and render the page depending on the clicked linkbutton, for example, showing an input box. How can I make sure that after I clicked the link button, the specified input box scrolls into view? Normally I would add something like #id to the url, but a linkbutton does not use an url. Suggestions? Thx!

    M 1 Reply Last reply
    0
    • L lustuyck

      Hi, I use linkbuttons on my page, and use the click events to do some stuff and render the page depending on the clicked linkbutton, for example, showing an input box. How can I make sure that after I clicked the link button, the specified input box scrolls into view? Normally I would add something like #id to the url, but a linkbutton does not use an url. Suggestions? Thx!

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

      Hi there, Depending on where you add some UI stuff, you can try with one of the following options to make sure that the user can see it: + Set the SmartNavigation attribute to true in the Page directive, for more information see Page.SmartNavigation Property[^] + You can emit some client script to automatically set focus on the specified input element when the page is loaded at the client side so that the user can see it. The sample code looks like this:

      private void LinkButton1_Click(object sender, System.EventArgs e)
      {
      //Add a TextBox to the PlaceHolder.
      TextBox txtBox = new TextBox();
      txtBox.ID = "txtBoxID";
      PlaceHolder1.Controls.Add(txtBox);

      //Emit script to set focus on the TextBox at the client side.		 
      RegisterFocusScript(txtBox);
      

      }

      private void RegisterFocusScript(System.Web.UI.Control control)
      {

      string script = "<script language=\\"javascript\\">";
      script += "window.document.getElementById(\\"" + control.ClientID + "\\").focus();";
      script += "</script>";
                      
      this.RegisterStartupScript("clientFocusScript", script);
      

      }

      L 1 Reply Last reply
      0
      • M minhpc_bk

        Hi there, Depending on where you add some UI stuff, you can try with one of the following options to make sure that the user can see it: + Set the SmartNavigation attribute to true in the Page directive, for more information see Page.SmartNavigation Property[^] + You can emit some client script to automatically set focus on the specified input element when the page is loaded at the client side so that the user can see it. The sample code looks like this:

        private void LinkButton1_Click(object sender, System.EventArgs e)
        {
        //Add a TextBox to the PlaceHolder.
        TextBox txtBox = new TextBox();
        txtBox.ID = "txtBoxID";
        PlaceHolder1.Controls.Add(txtBox);

        //Emit script to set focus on the TextBox at the client side.		 
        RegisterFocusScript(txtBox);
        

        }

        private void RegisterFocusScript(System.Web.UI.Control control)
        {

        string script = "<script language=\\"javascript\\">";
        script += "window.document.getElementById(\\"" + control.ClientID + "\\").focus();";
        script += "</script>";
                        
        this.RegisterStartupScript("clientFocusScript", script);
        

        }

        L Offline
        L Offline
        lustuyck
        wrote on last edited by
        #3

        Hi, thank you! I already did try the javascript method, and it works fine in IE, but in Mozilla Firefox the textbox gets the focus but the windows is not scrolling down to the textbox.... maybe I should also use window.scrollto or something like that..... The first solution I haven't tried yet.... will do so.

        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