ScrollIntoView for postback and async postback events

serkan sendur 0 Tallied Votes 329 Views Share

Set page's scroll position programmatically according to server side processing

//this two generic methods will be put in the class file(where utilities exist)


// if the control is a postback control 

 public static void ScrollIntoView(Control controlToScroll)
    {
        Page page = HttpContext.Current.Handler as Page;
        page.RegisterStartupScript("key2", "<script> document.getElementById('" + controlToScroll.ClientID + "').scrollIntoView();</script>");
    }

// if the control is an asyncronous postback control 
    public static void ScrollIntoViewForAsync(Control controlToScroll)
    {
        Page page = HttpContext.Current.Handler as Page;
        ScriptManager.RegisterClientScriptBlock(page, typeof(page), "key2", "document.getElementById('" + controlToScroll.ClientID + "').scrollIntoView();", true);
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.