Click here to Skip to main content
15,904,653 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C#
protected void grdArchive_PageIndexChanging(object sender, GridViewPageEventArgs e)
   {
       grdArchive.PageIndex = e.NewPageIndex;
       GetArchive();

       System.Text.StringBuilder sb = new System.Text.StringBuilder();
       sb.Append("<script language='javascript'>");
       sb.Append(" window.scrollTo(0,0);");
       sb.Append("</script>");
       System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "JCall1", sb.ToString(), false);
   }

I have added this JavaScript code inside GridView event grdArchive_PageIndexChanging for going to top of the page after grid refresh with new data, but this is not working.

Please help me to do this.
Posted
v3
Comments
Have you used any AJAX features like Update Panel or something?
KuntalBose 20-Dec-12 3:15am    
yes i used update panel.and i want to do this process within the update panel.you can see the page http://www.goodnewstab.com/archive[^]
Please check my answer.
Thanks...

1 solution

Use PageIndexChanged Event instead of PageIndexChanging Event.
And no need to use string buider to append the script tags.
Just the JavaScript code will do.
C#
protected void grdArchive_PageIndexChanged(object sender, EventArgs e)
{
      System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax_client_script", "window.scrollTo(0,0);", true);
}

Try this and let me know.

Thanks...
 
Share this answer
 
Comments
KuntalBose 20-Dec-12 7:12am    
nothing is happen
Try giving the alert and test like below...

System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax_client_script", "alert("Called");", true);
KuntalBose 20-Dec-12 7:21am    
alert is working fine but window.scrollTo(0,0); not working in gride and also a button click http://www.goodnewstab.com/subcription
What I have to do this link?
You have one live website, right?
So, can you show me where you implemented the alert?
Link to the Page?
KuntalBose 20-Dec-12 7:45am    
i tried with the alert in local and live this is work fine but this window.scrool(0,0) not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900