Scroll control into view after postback
-
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!
-
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!
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);
}
-
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);
}
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.