As you know it is very easy to scroll a page in ASP.Net, by defining an anchor tag you can do this but in this article I am going to explain for you how to a scroll page from server side with the help of JavaScript method scrollIntoView.For that you have to write JavaScript like the following in code behind. Here I have defined one method in code behind.
public void ScrollToMyFavouriteControl(System.Web.UI.Control ctrl){ System.Text.StringBuilder script = new System.Text.StringBuilder(); string clientID = ctrl.ClientID; script.Append("<script type='text/javascript'>"); script.Append("try {"); script.Append("document.getElementById('" + clientID + "').scrollIntoView(true);"); script.Append("document.getElementById('" + clientID + "').focus();"); script.Append("} catch (e) {}"); script.Append("</script>"); RegisterStartupScript("setScrollAndFocus", script.ToString());}
public void ScrollToMyFavouriteControl(System.Web.UI.Control ctrl){ System.Text.StringBuilder script = new System.Text.StringBuilder(); string clientID = ctrl.ClientID; script.Append("<script type='text/javascript'>"); script.Append("try {"); script.Append("document.getElementById('" + clientID + "').scrollIntoView(true);"); script.Append("document.getElementById('" + clientID + "').focus();"); script.Append("} catch (e) {}"); script.Append("</script>"); RegisterStartupScript("setScrollAndFocus", script.ToString());
public void ScrollToMyFavouriteControl(System.Web.UI.Control ctrl)
{
System.Text.StringBuilder script = new System.Text.StringBuilder();
string clientID = ctrl.ClientID;
script.Append("<script type='text/javascript'>");
script.Append("try {");
script.Append("document.getElementById('" + clientID + "').scrollIntoView(true);");
script.Append("document.getElementById('" + clientID + "').focus();");
script.Append("} catch (e) {}");
script.Append("</script>");
RegisterStartupScript("setScrollAndFocus", script.ToString());
}
if (!Page.IsStartupScriptRegistered("setScrollAndFocus")){ ScrollToMyFavouriteControl(TextBoxMyFavourite);}
if (!Page.IsStartupScriptRegistered("setScrollAndFocus")){ ScrollToMyFavouriteControl(TextBoxMyFavourite);
if (!Page.IsStartupScriptRegistered("setScrollAndFocus"))
ScrollToMyFavouriteControl(TextBoxMyFavourite);
public void ScrollToMyFavouriteControl(System.Web.UI.Control ctrl){ System.Text.StringBuilder script = new System.Text.StringBuilder(); string clientID = ctrl.ClientID; script.Append("<script type='text/javascript'>"); script.Append("try {"); script.Append("document.getElementById('" + clientID + "').scrollIntoView(true);"); script.Append("document.getElementById('" + clientID + "').focus();"); script.Append("} catch (e) {}"); script.Append("</script>"); Page.ClientScript.RegisterStartupScript(this.GetType(),"setScrollAndFocus", script.ToString());}
public void ScrollToMyFavouriteControl(System.Web.UI.Control ctrl){ System.Text.StringBuilder script = new System.Text.StringBuilder(); string clientID = ctrl.ClientID; script.Append("<script type='text/javascript'>"); script.Append("try {"); script.Append("document.getElementById('" + clientID + "').scrollIntoView(true);"); script.Append("document.getElementById('" + clientID + "').focus();"); script.Append("} catch (e) {}"); script.Append("</script>"); Page.ClientScript.RegisterStartupScript(this.GetType(),"setScrollAndFocus", script.ToString());
Page.ClientScript.RegisterStartupScript(this.GetType(),"setScrollAndFocus", script.ToString());
if (!ClientScript.IsStartupScriptRegistered("setScrollAndFocus")){ ScrollToMyFavouriteControl(TextBoxMyFavourite);}
if (!ClientScript.IsStartupScriptRegistered("setScrollAndFocus")){ ScrollToMyFavouriteControl(TextBoxMyFavourite);
if (!ClientScript.IsStartupScriptRegistered("setScrollAndFocus"))
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: