P
Peter
I want to call a JavaScript on PageIndexChanged event, how do I do that?
Thank You
Peter
Thank You
Peter
Subject: Re: GridView PageIndexChanged
Date: Thu, 24 Jul 2008 00:13:16 -0500
Steven Cheng said:Thanks for your prompt reply Peter,
Now I got that you want to do some resizing work on the GridView after
page
index changes, then I think the first approach I mentioned earlier (about
emiting script in "PageIndexChanged" event should work.
As you said that the "alert" didn't popup, I think there might be
something
else cause this. Is your page a standard ASP.NET page, or have you used
any
AJAX feature such as updatepanel? There might be some problem with some
GridView events in updatepanel.
Here is my complete page code for the test(a standard simple aspx page):
======================
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="id"
DataSourceID="SqlDataSource1"
onpageindexchanged="GridView1_PageIndexChanged"
onprerender="GridView1_PreRender" PageSize="2">
<Columns>
<asp:BoundField DataField="id" HeaderText="id"
ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="name"
SortExpression="name" />
<asp:BoundField DataField="age" HeaderText="age"
SortExpression="age" />
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testdbConnectionString %>"
SelectCommand="SELECT [id], [name], [age] FROM [persons]">
</asp:SqlDataSource>
</form>
============================
========code behind=============
protected void GridView1_PageIndexChanged(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(),
"page_index_script", "alert('page index changed!');", true);
}
=================
Also, you can just define a javascript function statically in the aspx
template and reference it in the "RegisterStartupScript" function's
parameter. If necessary, I can send you the web project contains the page
for testing. Please feel free to let me know if there is anything else
different.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------Subject: Re: GridView PageIndexChanged
Date: Thu, 24 Jul 2008 00:13:16 -0500The suggested code 'ClientScript.RegisterStartupScript(this.GetType(), ' is
not working nothing happens - when I click on #2 page in the GridView
the event fires but alert never appears.
I have JavaScript resizing code, when the window is resized I use JavaScript
to resize the GridView so it is resized with the window. But when a user
clicks on the pager the GridView resizes to its original size which does not
fit into the window. So I want to call the client JavaScript after user
clicks on the pager just like I do when the window is resized.
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
<[email protected]>
From: "Peter" <[email protected]>
Subject: Re: GridView PageIndexChanged
Date: Fri, 25 Jul 2008 13:07:35 -0500