This is a migrated thread and some comments may be shown as answers.

PageIndexChanged and PageSizeChanged fire twice

2 Answers 266 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jolynice
Top achievements
Rank 1
jolynice asked on 02 Jan 2011, 03:45 AM
Hi everyone and happy new year to all coders.

My problem is , I have a radgrid with custom paging, (based on Grid/Pager Template) i put a linkbutton and a textbox filter to load with data the radgrid 
When a write something to find in the textbox filter the radgrid it´s loaded correctly, the linkbutton it´s call one time.
When a click in the button (first, prev, next, last ) work ok to, but when I change the page size in the radcombox the RadGrid1_PageSizeChanged is called twice and if a write the number of the page in the RadNumericTextBox, the RadGrid1_PageIndexChanged it´s called one and then the LinkButton1_Click also.
Anyone can say what i am missing here?

I put here all the code.
Thank in advance.

Jolynice

ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="example.aspx.cs" Inherits="OralOffice_Pacientes_example" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div>
     <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
 
     <script type="text/javascript">
            var tableView = null;
            function pageLoad(sender, args) {
                tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
            }
 
            function RadComboBox1_SelectedIndexChanged(sender, args) {
                tableView.set_pageSize(sender.get_value());
            }
 
            function changePage(argument) {
                tableView.page(argument);
            }
 
            function RadNumericTextBox1_ValueChanged(sender, args) {
                tableView.page(sender.get_value());
            }
        </script>
 
    </telerik:RadScriptBlock>
 
            <!-- content start -->
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
 
            <div>
 
 
            <asp:Button ID="LinkButton1" runat="server"  Text="Find CompanyName" onclick="LinkButton1_Click">
            </asp:Button>  
            <input type="text" runat="server" name="fname" id="Text1"  style="width:370px;"/>
 
            </div>
 
            <telerik:RadGrid ID="RadGrid1" AllowPaging="true"
            DataSourceID="SqlDataSource1" runat="server" Skin="Vista"
            OnPageIndexChanged="RadGrid1_PageIndexChanged" onPagesizechanged="RadGrid1_PageSizeChanged">
                <MasterTableView>
                    <PagerTemplate>
                        <asp:Panel ID="PagerPanel" Style="padding: 6px; line-height: 24px" runat="server">
                            <div style="float: left">
                                <span style="margin-right: 3px;">Page size:</span>
                                <telerik:RadComboBox ID="RadComboBox1" DataSource="<%# new object[]{10, 20, 30, 40, 50} %>"
                                    Style="margin-right: 20px;" Width="40px" SelectedValue='<%# DataBinder.Eval(Container, "Paging.PageSize") %>'
                                    runat="server" OnClientSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
                                </telerik:RadComboBox>
                            </div>
                            <div style="margin: 0px; float: right;">
                                Displaying page
                                <%# (int)DataBinder.Eval(Container, "Paging.CurrentPageIndex") + 1 %>
                                of
                                <%# DataBinder.Eval(Container, "Paging.PageCount")%>
                                , items
                                <%# (int)DataBinder.Eval(Container, "Paging.FirstIndexInPage") + 1 %>
                                to
                                <%# (int)DataBinder.Eval(Container, "Paging.LastIndexInPage") + 1 %>
                                of
                                <%# DataBinder.Eval(Container, "Paging.DataSourceCount")%>
                            </div>
                            <div style="width: 400px; margin: 0px; padding: 0px; float: left; margin-right: 10px;
                                white-space: nowrap;">
                                <asp:Button ID="Button1" runat="server"  OnClientClick="changePage('first'); return false;"
                                    CommandName="Page" CommandArgument="First" Text="|<" CssClass="PagerButton FirstPage" />
                                <asp:Button ID="Button2" runat="server" OnClientClick="changePage('prev'); return false;"
                                    CommandName="Page" CommandArgument="Prev" Text=" <" CssClass="PagerButton PrevPage" />
                                <span style="vertical-align: middle;">Page:</span>
                                <telerik:RadNumericTextBox ID="RadNumericTextBox1" Width="25px" Value='<%# (int)DataBinder.Eval(Container, "Paging.CurrentPageIndex") + 1 %>'
                                    runat="server">
                                    <ClientEvents OnValueChanged="RadNumericTextBox1_ValueChanged" />
                                    <NumberFormat DecimalDigits="0" />
                                </telerik:RadNumericTextBox>
                                <span style="vertical-align: middle;">of
                                    <%# DataBinder.Eval(Container, "Paging.PageCount")%>
                                </span>
                                <asp:Button ID="Button3" runat="server" OnClientClick="changePage('next'); return false;"
                                    CommandName="Page" CommandArgument="Next" Text=" >" CssClass="PagerButton NextPage" />
                                <asp:Button ID="Button4" runat="server" OnClientClick="changePage('last'); return false;"
                                    CommandName="Page" CommandArgument="Last" Text=" >|" CssClass="PagerButton LastPage" />
                            </div>
                            <asp:Panel runat="server" ID="NumericPagerPlaceHolder" />
                        </asp:Panel>
                    </PagerTemplate>
                    <PagerStyle Mode="NumericPages" PageButtonCount="10" />
                </MasterTableView>
            </telerik:RadGrid>
            <br />
            <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                ProviderName="System.Data.SqlClient"
                SelectCommand="SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City FROM Customers"
                runat="server"></asp:SqlDataSource>
            <!-- content end -->
    </div>
    </form>
</body>
</html>

C#
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class OralOffice_Pacientes_example : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            setdatasourceGrid();
            RadGrid1.DataBind();
        }
    }
 
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        setdatasourceGrid();
        RadGrid1.DataBind();
    }
 
 
    internal void setdatasourceGrid()
    {
        //To see the headers only
        if (String.IsNullOrEmpty(Text1.Value))
            SqlDataSource1.SelectCommand = "SELECT top 0 CustomerID, CompanyName, ContactName, ContactTitle  FROM  Customers ";
        //To see all records
        else if (Text1.Value.Equals("*"))
            SqlDataSource1.SelectCommand = "SELECT  CustomerID, CompanyName, ContactName, ContactTitle  FROM  Customers ";
        //filter
        else
            SqlDataSource1.SelectCommand = "SELECT CustomerID, CompanyName, ContactName, ContactTitle  FROM  Customers  WHERE  (CompanyName like  '%" + Text1.Value + "%')";
    }
 
 
    protected void RadGrid1_PageIndexChanged(object source, Telerik.Web.UI.GridPageChangedEventArgs e)
    {
        RadGrid1.CurrentPageIndex = e.NewPageIndex;
        setdatasourceGrid();
        RadGrid1.DataBind();
    }
 
    protected void RadGrid1_PageSizeChanged(object source, Telerik.Web.UI.GridPageSizeChangedEventArgs e)
    {
        setdatasourceGrid();
        RadGrid1.DataBind();
    }
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Marin
Telerik team
answered on 07 Jan 2011, 08:27 AM
Hello jolynice,

The button by default is interpreted as a submit button for the page and that is why its click event fires when you press enter. To solve this problem set UseSubmitBehavior="false" property for the button.
Additionally the PageSizeChanged event is fired twice because the first time its raised from the MasterTableView for the grid (when setting it client side) and it bubbles up and the second time it is raised from the grid itself.

Best wishes,
Marin
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
jolynice
Top achievements
Rank 1
answered on 09 Jan 2011, 12:45 AM
Hello Telerik Admin,

You are right i forgot one thing trivial like the submit of the button :(

Thanks for the reply

Tags
Grid
Asked by
jolynice
Top achievements
Rank 1
Answers by
Marin
Telerik team
jolynice
Top achievements
Rank 1
Share this question
or