I have the following code at the end of my aspx page. When I click on the button below, the usercontrol loads a grid. The problem is that when that grid is loaded it's out of the viewed range, and the user has to scroll to the botton to view the displayed grid.
<asp:UpdatePanel runat="server">
<ContentTemplate>
<div style="border: thin; border-style: double">
<asp:Panel ID="PnlRequired" runat="server" DefaultButton="BntOpenGridView_Click">
<table style="width: 100%">
<tr width="100%">
<td>
<asp:ImageButton ID="BtnOpenGridView" Visible="false" OnClick="BntOpenGridView_Click" runat="server" ImageUrl="~/Images/find1.png" Width="2.5%" />
</td>
</tr>
<tr>
<td>
<UserControl:RequiredGridView runat="server" ID="RqGrdView"></UserControl:KeywordsGridView>
</td>
</tr>
<tr>
<asp:Label ID="lblErrorMessage2" runat="server" ForeColor="Red"></asp:Label>
</tr>
</table>
</asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
What I'm trying to do is to use javascript some way to scroll to the bottom of the page after displaying the grid. Here's what i've tried:
<script type="text/javascript">
function ScrollToGrid()
{
document.getElementById('RqGrdView').scrollIntoView(true);
}
</script>
In the Button Click event after triggering the usercontrol to load the gridview I added the following code:
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "focusOnGrid", "ScrollToKeywordsGridView()", true);
This didn't work
I also tried to add the same code to Page PreRender as follows:
protected void BntOpenGridView_Click(object sender, ImageClickEventArgs e)
{
isRequiredGridViewClicked = true;
// code to load gridview in usercontrol
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (isRequiredGridViewClicked)
{
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "focusOnGrid", "ScrollToGridView()", true);
isRequiredGridViewClicked = false;
}
}
This also didn't work, the javascript fires OK, but the gridview is not not displayed in full and the user has to scroll manually.