ListView Pagination Lost in Cross Page Postback

3 posts, 0 answers
  1. Meengla
    Meengla avatar
    2 posts
    Member since:
    Jan 2011

    Posted 31 Jan 2011 Link to this post

    Hi,
    I am post form data from, say, source.aspx to destination.aspx page. The source.aspx page has some checkboxes which are used in a SQL query in the destination.aspx page. For example,

     if (Request.Form["color_spice"] != null) { WhereClause += " OR ado_products_fabrics.color = 'spice'"; }

    The first time the destination page loads the RadListView shows the pagination fine. However, clicking on the RadDataPager under the RadListView causes a postback where the source.aspx page's Form data are lost. I have tried using PreviousPage.FindControl() method but that too does not resolve in the pagination's postback.

    So what can I do? I don't want to use Session variables--there are going to be dozens of controls from the source.aspx page passing values to destination.aspx page. Cookies too will be too much to track then?

    Below are the code-fragments for the .aspx and the .cs files.

    Thanks!

    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadListView1">
                    <UpdatedControls>
                         
                        <telerik:AjaxUpdatedControl ControlID="ListViewPanel1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <div style="width: 880">
         <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Black">
            </telerik:RadAjaxLoadingPanel>
            <asp:Panel ID="ListViewPanel1" runat="server">
            <telerik:RadListView ID="RadListView1" runat="server" DataKeyNames="fabricid" AllowPaging="True">
                <LayoutTemplate>
                    <div class="RadListView RadListViewFloated RadListView_Default">
                        <div class="rlvFloated">
                            <div id="itemPlaceholder" runat="server">
                            </div>
                        </div>
                    </div>
                     <telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="RadListView1">
                <Fields>
                    <telerik:RadDataPagerButtonField FieldType="Numeric"  />
                </Fields>
            </telerik:RadDataPager>
                </LayoutTemplate>
    .....


    protected void Page_Load(object sender, EventArgs e)
       {
           String WhereClause = string.Empty;
         
           //determine which button clicked http://stackoverflow.com/questions/1099020/asp-net-cross-page-posting
           if (Request.Form["btnTextGeneric"] != null)
           {
               // do button 1 stuff
     
           }
           else if (Request.Form["btnCBFabrics"] != null)
           {
                 /////COLORS
              if (Request.Form["color_spice"] != null) { WhereClause += " OR ado_products_fabrics.color = 'spice'"; }
         .....
    if (WhereClause != "")
           {
               RadListView1.DataSource = GetDataTable("SELECT * FROM [ado_products_fabrics] WHERE 0 = 1" + WhereClause);
           }
           else
           {
               RadListView1.DataSource = GetDataTable("SELECT * FROM [ado_products_fabrics]");
           }
                
               RadListView1.DataBind();

  2. Martin
    Admin
    Martin avatar
    802 posts
    Member since:
    Sep 2012

    Posted 03 Feb 2011 Link to this post

    Hello Meengla,

    I am afraid that there is no other option than saving the where clause when the destination page is loaded for first time. The exact approach you will use to save the data (session, viewstate, cookie, etc.) does not affect the ListView control. However you will have to ensure that the correct data source is set to the ListView in any case that requires it to rebind (paging, sorting, etc).

    I hope this helps.

    Best wishes,
    Martin
    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.

  3. Meengla
    Meengla avatar
    2 posts
    Member since:
    Jan 2011

    Posted 03 Feb 2011 Link to this post

    Hi Martin,
    Thank you for your help. I was able to fix the problem by using Cookies. Works like a charm. If Cookies are not set then the 'Where' clause does not get stored and hence all records from the database are returned. Not ideal but then still better than Session based storage.
    Meengla

Back to Top