0
votes

Actually I am trying to scroll the page after post back happened by delete button. I tried to call JavaScript function from button click event and the button is in gridview. But javascript function is not calling. And I want to call the JavaScript function from code-behind only not through OnClientClick event. Please help me

 protected void btnDelete_Click(object sender, EventArgs e)
    {
    string pos = hdnfield.Value;
    GridViewRow currentRow = (GridViewRow)((Button)sender).Parent.Parent;
    Button btnDelete= (Button)currentRow.FindControl("btnDelete");
    long ImageId = Convert.ToInt64(gridImages.DataKeys[currentRow.RowIndex]["IMAGE_ID"].ToString());
    bool bRetValue = DeleteImage(ImageId);

    ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:scrollTo('" + pos + "')", true);

    }



function scrollTo(val) {
$('html').scrollTop(val);
}


<asp:GridView ID="gridImages"  runat="server" AutoGenerateColumns="False"
Height="234px" Width="368px" ShowHeader="false" BorderStyle="None" style="border-collapse:separate; border-spacing:20px;" GridLines="None" DataKeyNames ="IMAGE_ID">

<Columns>
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%#"ShowImages.ashx?ImgID="+ Eval("IMAGE_ID") %>' Height="78px" Width="118px" style="border:3px solid #CCCCFF"/>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:Button ID="btnDelete" runat="server" Text="Delete"  
OnClick="btnDelete_Click"/> 
 </ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
1
Don't use codebehind :) - jcarpenter2

1 Answers

0
votes

Try this instead:

ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "scrollTo('" + pos + "');", true);

Also, I noticed that your Javascript function may be incorrect.

function scrollTo(val) {
    $('html').scrollTop(pos);
}

I assume you want to use the val parameter in the scrollTop method.

function scrollTo(val) {
    $('html').scrollTop(val);
}