asp.net - Executing JavaScript after a GridView's paging callback -
i have gridview enablesortingandpagingcallbacks enabled. when user clicks change pages, callback performed , gridview updated. need run javascript function after happens can perform client-side actions on new page of data. how can accomplish this?
the closest i've found question this: how have javascript callback executed after update panel postback?. however, using pageload() function won't work here because pageload() doesn't seem triggered after gridview callback.
i need have work ie7, or otherwise i'd use domsubtreemodified event listener.
sample code gridview1_pageindexchanging , pageload won't fire.
<%@ page language="c#" autoeventwireup="true" codefile="test_script.aspx.cs" inherits="test_script" %> <%@ register assembly="ajaxcontroltoolkit" namespace="ajaxcontroltoolkit" tagprefix="asp" %> <form id="form1" runat="server"> <asp:toolkitscriptmanager id="scriptmanager1" runat="server" scriptmode="release" /> <asp:gridview id="gridview1" runat="server" allowpaging="true" enablesortingandpagingcallbacks="true" datasourceid="sqldatasource1" onpageindexchanging="gridview1_pageindexchanging" /> </form> <script type="text/javascript"> function pageload(sender, args) { alert('pageload'); } </script>
code behind:
public partial class test_script : system.web.ui.page { protected void page_load(object sender, eventargs e) { } protected void gridview1_pageindexchanging(object sender, gridviewpageeventargs e) { // doesn't fire when enablesortingandpagingcallbacks set true } }
in above code, pageload() fires when page first loaded not fire after gridview paged. in code behind, page_load fires when gridview paged gridview1_pageindexchanging() not.
if change enablesortingandpagingcallbacks false, functions fire expect on each gridview page change.
this should work:
protected sub gridview1_pageindexchanging(byval sender object, byval e system.web.ui.webcontrols.gridviewpageeventargs) handles gridview1.pageindexchanging me.gridview1.pageindex = e.newpageindex bindgridview() 'this binds control if not clientscript.isclientscriptblockregistered(me.gettype(), "myscript") scriptmanager.registerclientscriptblock(me.gridview1, me.gettype(), "myscript", "alert('done paging');", true) end if end sub
since did not specify language used first 1 opened visual studio.
Comments
Post a Comment