Reset scroll position after Async postback - ASP.NET

前端 未结 8 1408
花落未央
花落未央 2020-11-30 06:08

What is the best way to reset the scroll position to the top of page after the an asynchronous postback?

The asynchronous postback is initiated from a ASP.NET Grid

8条回答
  •  再見小時候
    2020-11-30 06:49

    Here is the following solution I developed based on this source

    ASP.NET Webform

     
    
    
        
            
        
    
    

    ASP.NET Webform code behind

    protected void MyGridView_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        if(e.Row.RowType.Equals(DataControlRowType.DataRow))
        {
            foreach (DataControlFieldCell cell in e.Row.Cells)
            {
                foreach(Control control in cell.Controls)
                {
                    LinkButton lb = control as LinkButton;
    
                    if (lb != null && lb.CommandName == "Edit")
                        lb.Attributes.Add("onclick", "SetScrollEvent();");
                }
            }
        }
    }
    

提交回复
热议问题