zoukankan      html  css  js  c++  java
  • How to scroll an ASP.NET control into view after page load using codebehind

    Introduction
    In some cases when an ASP.NET page loads the control you need to focus on is not visible because it is further down the page. I have had numerous occasions where a request varible indicates which item on a long list the user is interested in viewing, this script can help by scrolling the particular item into view. 

    Code
    The following function I have added to a Utils.dll library for gerneral use so is static and needs the current page as a variable.

    public class Utils
    {
    public static void FocusControlOnPageLoad(string ClientID, System.Web.UI.Page page)

    {

    page.RegisterClientScriptBlock("CtrlFocus",

    @"<script> 

    function ScrollView()

    {
    var el = document.getElementById('"+ClientID+@"')if (el != null){el.scrollIntoView();
    el.focus();}
    }

    window.onload += ScrollView;

    </script>");

    }
    }

    You can use this as follows:

    private void Page_Load(object sender, System.EventArgs e)
    {
       Utils.FocusControlOnPageLoad(this.yourcontrol.ClientID, this.Page);
    }

  • 相关阅读:
    C#正则表达式
    HDU 1009 FatMouse' Trade
    HDU 1022 Train Problem I
    HDU 3665 Seaside
    (转)qsort完整版用法
    HDU 1061 Rightmost Digit (矩阵快速幂)
    HDU 2817 A sequence of numbers
    HDU 1943 Ball bearings
    HDU 1058 Humble Numbers
    HDU 4278 Faulty Odometer
  • 原文地址:https://www.cnblogs.com/stone/p/117890.html
Copyright © 2011-2022 走看看