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

[Solved] Paging post back problem

1 Answer 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Samar Hamdan
Top achievements
Rank 1
Samar Hamdan asked on 12 Oct 2009, 03:03 PM

Dears,
I am working on a composite custom control contains a radGrid control, I faced the following problem in the RadGrid Paging,
i have set the RadAjaxManager to enable the Ajax paging for my grid so that it shouldn't postback on each page number change,
unfortunately, it is doing postback on each page index change and it is not passing by the 
GridNeedDataSourceEventHandler
Please check below code sample and help me to fix this issue,

Any help will be highly appreciated,

protected override void OnInit(EventArgs e)  
        {   
            //grdTransactionsList  
            grdTransactionsList.ID = "grdTransactionsList";  
            grdTransactionsList.Skin = "Office2007";  
            grdTransactionsList.AutoGenerateColumns = false;  
            grdTransactionsList.AllowPaging = true;  
            grdTransactionsList.AllowCustomPaging = true;  
            grdTransactionsList.PageSize = Constants.PageSize;  
            grdTransactionsList.Visible = true;  
            grdTransactionsList.NeedDataSource += new GridNeedDataSourceEventHandler(grdTransactionsList_NeedDataSource);  
            grdTransactionsList.PagerStyle.Mode = GridPagerMode.NumericPages;  
            grdTransactionsList.MasterTableView.GridLines = GridLines.None;  
            grdTransactionsList.MasterTableView.AutoGenerateColumns = false;  
            grdTransactionsList.MasterTableView.TableLayout = GridTableLayout.Auto;  
            InitilizeTransactionsListColumns();  
            grdTransactionsList.ClientSettings.Selecting.AllowRowSelect = true;  
            grdTransactionsList.ClientSettings.EnableRowHoverStyle = true;  
 
            //Check if there is already added ScriptManager to this Page, Only one Script Manager Instance can be in the page  
            if (ScriptManager.GetCurrent(this.Page) == null)  
            {  
                scriptManager = new ScriptManager();  
                scriptManager.ID = "ScriptManager1";  
            }  
            if (RadAjaxManager.GetCurrent(this.Page) == null)  
            {  
                radAjaxManager = new RadAjaxManager();  
                radAjaxManager.ID = "RadAjaxManager";  
                  
                radAjaxLoadingPanel = new RadAjaxLoadingPanel();  
                radAjaxLoadingPanel.ID = "pnlRadAjaxLoadingPanel";  
                radAjaxLoadingPanel.Height = new Unit(50);  
                radAjaxLoadingPanel.Width = new Unit(50);  
                radAjaxLoadingPanel.Transparency = 30;  
                Image imgLoading = new Image();  
                imgLoading.ID = "imgLoading";  
                radAjaxLoadingPanel.Controls.Add(imgLoading);  
                radAjaxManager.DefaultLoadingPanelID = radAjaxLoadingPanel.ID;  
            }  
        }  
 
 protected override void CreateChildControls()  
        {  
            if (scriptManager != null)  
                Controls.Add(scriptManager);  
            if (radAjaxManager != null)  
                Controls.Add(radAjaxManager);  
            if (radAjaxLoadingPanel != null)  
                Controls.Add(radAjaxLoadingPanel);  
 
            if (RadAjaxManager.GetCurrent(this.Page) != null)  
            {  
                AjaxSetting ajaxSetting = new AjaxSetting     (grdTransactionsList.ID);  
                ajaxSetting.UpdatedControls.Add(new AjaxUpdatedControl(grdTransactionsList.ID, radAjaxLoadingPanel.ID));  
                RadAjaxManager.GetCurrent(this.Page).AjaxSettings.Add(ajaxSetting);  
            }  
                Controls.Add(new LiteralControl("<table>"));  
                Controls.Add(new LiteralControl("   <tr>"));  
                Controls.Add(new LiteralControl("        <td>"));  
                Controls.Add(grdTransactionsList);  
                Controls.Add(new LiteralControl("        </td>"));  
                Controls.Add(new LiteralControl("   </tr>"));  
                Controls.Add(new LiteralControl("</table>"));  
        }  
  protected void grdTransactionsList_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            if (!Page.IsPostBack)  
                return;  
            else  
            {  
                try  
                {  
                    int totalRecords = 0;  
                    grdTransactionsList.DataSource = Presenter.GetTransactionsList(out totalRecords);  
                    grdTransactionsList.VirtualItemCount = totalRecords;  
                }  
                catch (JoPayBusinessException ex)  
                {  
                    ShowError(ex);  
                }  
            }  
        }  
//Presenter.GetTransactionsList(out totalRecords) will call below method  
 public void SetTransactionsGrid(IList<TransactionSearch> paymentTransactions, int totalRecords)  
        {  
            grdTransactionsList.DataSource = paymentTransactions;  
            grdTransactionsList.VirtualItemCount = totalRecords;  
            grdTransactionsList.DataBind();  
        } 

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 12 Oct 2009, 03:31 PM
Hello Samar,

Please have in mind you should never call DataBind() as well when using advanced data-binding through NeedDataSource.
For more information about NeedDataSource event and programmatic creation, please review the following articles:
http://www.telerik.com/help/aspnet-ajax/grdadvanceddatabinding.html
http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html
 
All the best,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Samar Hamdan
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or