samedi 27 décembre 2014

how to call javascript function from gridview button click event codebehind


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(pos);
}


<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>




Aucun commentaire:

Enregistrer un commentaire