Problem with my Custom paging code when I remove entries

6 posts, 0 answers
  1. Tim
    Tim avatar
    57 posts
    Member since:
    Apr 2011

    Posted 12 Sep 2012 Link to this post

    I am using a RadDataPager to allow my user to page through a series of records.

    I am successfully keeping track of every thing.
    I should mention I am doing this in code-behind.

    I respond to the OnCommand events, get the data, and present each record as they interact with the pagination.

    I also want to allow them to add and delete data.

    I respond to the TotalRowCount request which seems to get triggered when I issue a FireCommand evet at the DataPager.

    Everything works well on the add. The Total row count and current page is updated and the user is positioned on the correct data.

    However when I want to remove an entry the current page value in the UI is set to 1.

    Now the data being presented is incorrect and if they click Next my code traps because my internal index is set to the wrong value.

    I am firing a command with my desired page number but it always sets the DataPage to page 1.

    My current work around is to set my internal index to zero.
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 17 Sep 2012 Link to this post

    Hi Tim,

    Could you share your code using the CODE FROMATTER tool of the ticket editor. What type of control are you paging?

    Greetings,
    Tsvetoslav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tim
    Tim avatar
    57 posts
    Member since:
    Apr 2011

    Posted 17 Sep 2012 Link to this post

    Here is my ascx code.
    As you can see I am not directly [aging any controls.
    FYI There are numerous extra controls after the txtSvrAddress control in their own table rows
    I didn't include them to make the code more concise.

    <
    telerik:RadAjaxManagerProxy ID="rampCertificateAuthorityControl" runat="server"
        <AjaxSettings
      
            <telerik:AjaxSetting AjaxControlID="RadDataPager1"
                <UpdatedControls
                    <telerik:AjaxUpdatedControl ControlID="RadDataPager1" />
                    <telerik:AjaxUpdatedControl ControlID="table" />
                </UpdatedControls
            </telerik:AjaxSetting
      
        </AjaxSettings
    </telerik:RadAjaxManagerProxy
      
    <div style="width:100%; height:100%;">
         <fieldset style="width:660px;"><legend>Definition</legend>
      
            <asp:Table ID="tableMaster" runat="server" Width="629px">  
                <asp:TableRow>
                    <asp:TableCell>
                        <telerik:RadButton ID="btnAdd" runat="server" Text="Add" OnClick="btnAddM_OnClientClicked"
                            ToolTip="Add new CA" Enabled="True" BorderStyle="None" ClientIDMode="Static"
                            Icon-PrimaryIconUrl="~/Images/toolbar/new.png" AutoPostBack="True" Visible="True" 
                            ButtonType="LinkButton" CssClass="alignmiddle" Font-Underline="True" Style="vertical-align: middle" >
                        </telerik:RadButton>
                      
                        <telerik:RadButton ID="btnDel" runat="server" Text="Delete" OnClick="btnDelM_OnClientClicked"
                            ToolTip="Delete current CA" Enabled="True" BorderStyle="None" ClientIDMode="Static"
                            Icon-PrimaryIconUrl="~/Images/toolbar/delete.png" AutoPostBack="True" Visible="True"
                            ButtonType="LinkButton" CssClass="alignmiddle" Font-Underline="True" Style="vertical-align: middle" >
                        </telerik:RadButton>
      
                        <asp:Label ID="lblCertError" Visible="true" runat="server" Text="" ForeColor="Red"></asp:Label>
      
                    </asp:TableCell>
                </asp:TableRow>                               
                <asp:TableRow>
                    <asp:TableCell>
                        <telerik:RadDataPager ID="RadDataPager1" runat="server" 
                                OnCommand="rdpCertificateAuthority_OnCommand"
                                OnTotalRowCountRequest="rdpCertificateAuthority_TotalRowCountRequest" 
                                OnPageIndexChanged="rdpCertificateAuthority_PageIndexChanged" PageSize="1" Width="645px">
                            <Fields>
                                <telerik:RadDataPagerButtonField FieldType="FirstPrev" HorizontalPosition="LeftFloat" />
                                <telerik:RadDataPagerGoToPageField CurrentPageText="Page: " TotalPageText=" of" 
                                    SubmitButtonText="Go" TextBoxWidth="30" />
                                <telerik:RadDataPagerButtonField FieldType="NextLast" />
                            </Fields>
                        </telerik:RadDataPager>
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>
      
            <asp:Table ID="table" runat="server" CaptionAlign="Right" Visible="true"
                <asp:TableRow>
                    <asp:TableCell>
                        <fieldset style="height: 100%; width: 630px; ">
                          
                            <legend>
                                Name:<telerik:RadTextBox ID="txtNameAdd" runat="server" 
                                    AutoCompleteType="Disabled" 
                                    TabIndex="300"
                                    Text=""
                                    Width="385px" MaxLength="50" ClientEvents-OnKeyPress="OnCertificateAuthorityTextBoxKeyPress">
                                </telerik:RadTextBox>
                            </legend>
      
                            <asp:Table ID="tableFields" runat="server">
                                <asp:TableRow>
                                    <asp:TableCell ColumnSpan="2">
      
                                        <asp:Label ID="lblNameRequired" runat="server" Width="170px" Text="! Required: Name." ForeColor="Red" style="padding-left: 40px;"
                                                Visible="False">
                                        </asp:Label>
      
                                           
                                    </asp:TableCell>
                                </asp:TableRow>
      
                                <asp:TableRow>
                                    <asp:TableCell HorizontalAlign="Right">
                                        HTTPS:     
                                    </asp:TableCell>
                                    <asp:TableCell style="padding-left: 12px;">
                                        <asp:CheckBox ID="chckHttps" runat="server" AutoPostBack="false" text="Enable" onclick="OnHttpsClicked(this);"
                                            width="75px" TabIndex="305" />
                                           
                                    </asp:TableCell>
                                </asp:TableRow>
      
                                <asp:TableRow>
                                    <asp:TableCell HorizontalAlign="Right">
                                        Server Address*:    
                                    </asp:TableCell>
                                    <asp:TableCell style="padding-left: 12px;">
                                        <telerik:RadTextBox ID="txtSvrAddress" runat="server" Width="270px"
                                            AutoCompleteType="Disabled" MaxLength="64" ClientEvents-OnKeyPress="OnCertificateAuthorityTextBoxKeyPress" TabIndex="306" />
      
                                           
                                      
                                        <asp:Label ID="lblSvrAddressRequired" runat="server" Width="70px" Text="! Required" ForeColor="Red"
                                                Visible="False">
                                        </asp:Label>
      
                                           
      
                                </asp:TableRow>
      
                             
                            </asp:Table>
                        </fieldset>
                    </asp:TableCell>
                </asp:TableRow>                            
            </asp:Table>
       
        </fieldset>

    Here is what I consider the relevant code behind.

    The btnDel event handler eventually triggers a FireCommand that I want to provide the desired index too.
    However when I trace into the OnCommand the argument always points to the first index.

    The intent of the OnCommand event handler is to look through my array of data entries and use the indicated 
    entry to populate my controls.

    On a related note, which I have included in a separate forum entry I would really like to cancel the OnCommand
    if the data isn't valid, but there seems to be no way to do this. 

             ///
    <summary>
           /// Event handler that responds to the click of the Delete button.
           /// </summary>
           /// <param name="sender"></param>
           /// <param name="e"></param>
           protected void btnDelM_OnClientClicked(object sender, EventArgs e)
           {
               ServerPropertiesServiceClient   svcConfig       = GlobalFunc.GetService<ServerPropertiesServiceClient>( Session, null );
               bool    bAllowDelete    = false;
               bool    bFound          = false;
               string  sDefintionID;
               int     iIndex;
               int     iCount;
               sDefintionID    = (string)m_alCertAuthIDs[m_iCurrentPage];
               iCount          = m_alCertAuths.Count;
               for ( iIndex = 0; iIndex < iCount; iIndex++ )
               {
                   if ( ((CertificateAuthorityEntry)m_alCertAuths[iIndex]).CertAuthDefinedSettingInfo.Id == sDefintionID )
                   {
                       bAllowDelete        = svcConfig.SafeToDeleteCertificateAuthority( sDefintionID );
                       bFound              = true;
                       break;
                   }
               }
               if ( bFound )
               {
                   if ( !bAllowDelete )
                   {
                       lblCertError.Text       = Resources.GlobalResources.CertAuthorityInUseError;
                   }
                   else
                   {
                       lblCertError.Text       = "";
                       ((CertificateAuthorityEntry)m_alCertAuths[iIndex]).Operation = CertificateOperations.Delete;
                       m_alCertAuthIDs.RemoveAt( m_iCurrentPage );
                       m_iCertCount            = m_alCertAuthIDs.Count;
                       // Check if the only remaining 'logical' Certificate Authority setting was just removed.
                       if ( m_iCertCount  < 1 )
                       {
                           // Since we just deleted the last remaining 'logical' Certificate Authority setting we need to revert to just the Add button.
                           this.ShowControls( false );
                       }
                       else
                       {
                           /*
                           // Check if the current page is the last page available,
                           // because if it is we need to decrement the current page index.
                           if ( m_iCurrentPage == m_alCertAuthIDs.Count )
                           {
                               //m_iCurrentPage--;
                               m_iCurrentPage = 0;
                           }*/
                           m_iCurrentPage = 0;
                           this.PresentSettingInfo( m_alCertAuthIDs, m_alCertAuths, m_iCurrentPage );
                       }
                       Dirty                   = true;
                       // Check if we just deleted the last 'logical' Certificate Authority, because if we did there is no need to update the pager.
                       if ( m_iCertCount > 0 )
                       {
                           RadDataPager1.FireCommand(RadDataPager.PageCommandName, m_iCurrentPage.ToString());
                       }
                   }
               }
           }
          
    /// <summary>
           /// Event handler that responds to ANY user interaction with the paging control.
           /// It manages the presentation of the appropriate Certificate Authority based on the current page setting.
           /// Prior to presenting the new information it also makes sure the current page data is placed into the local data state.
           /// In this way the user can make changes, page through their Certificate Authorities and only save their changes
           /// when the Save button is clicked.
           /// </summary>
           /// <param name="sender"></param>
           /// <param name="e"></param>
           protected void rdpCertificateAuthority_OnCommand(object sender, RadDataPagerCommandEventArgs e)
           {
               ServerPropertiesServiceClient svcConfig = GlobalFunc.GetService<ServerPropertiesServiceClient>(Session, null);
               if ( e.CommandName == "Page" )
               {
                   string s = e.CommandArgument.ToString();
                   // There is a case where this event handler gets fired even though there are no 'logical' Certificate Authorities left.
                   // So check before doing any work here.
                   // Also prevents an issue inside SaveUiSettingsToDataState.
                   if ( m_iCertCount > 0 )
                   {
                       this.SaveUiSettingsToDataState( m_alCertAuthIDs, m_alCertAuths, m_iCurrentPage );
                       if ( s.CompareTo( "Next" ) == 0 )
                       {
                           m_iCurrentPage++;
                       }
                       else if ( s.CompareTo( "Prev" ) == 0 )
                       {
                           m_iCurrentPage--;
                       }
                       else if ( s.CompareTo( "Last" ) == 0 )
                       {
                           m_iCurrentPage = m_iCertCount - 1;
                       }
                       else if ( s.CompareTo("First") == 0 )
                       {
                           m_iCurrentPage = 0;
                       }
                       else
                       {
                           m_iCurrentPage = Convert.ToInt32( s );
                       }
                     
                       this.PresentSettingInfo( m_alCertAuthIDs, m_alCertAuths, m_iCurrentPage );
                   }
               }
           }
           /// <summary>
           /// 
           /// </summary>
           /// <param name="sender"></param>
           /// <param name="eventArgs"></param>
           protected void rdpCertificateAuthority_PageIndexChanged(object sender, RadDataPagerPageIndexChangeEventArgs eventArgs)
           {
           }
           /// <summary>
           /// 
           /// </summary>
           /// <param name="sender"></param>
           /// <param name="eventArgs"></param>
           protected void rdpCertificateAuthority_TotalRowCountRequest(object sender, RadDataPagerTotalRowCountRequestEventArgs eventArgs)
           {
               eventArgs.TotalRowCount = m_iCertCount;
           }

    HTH
  5. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 20 Sep 2012 Link to this post

    Hello Tim,

    Thanks for the code. I could not see anything suspicious in your code except for the following statement in the OnCommand event:
    m_iCurrentPage = 0;

    Then when you fire the paging command you will position the pager at the beginning and as far as I understand this makes the pager go out of synchrony with your internal index (whichever that might be as I could not understand). Could you shed more light on why you are making the pager go to its first page and what the index is that goes out of step with the data pager control.

    Regards,
    Tsvetoslav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Tim
    Tim avatar
    57 posts
    Member since:
    Apr 2011

    Posted 20 Sep 2012 Link to this post

    Hi

    The line of code you call into question is responding to the user clicking on the 'First' button in the pager,
    so I need to set m_iCurrentIndex to zero.

    m_iCurrentIndex is in fact the internal index that was getting out of sync with the pager.

    I have made significant changes to my app and the problem seems to have gone away.

    Thanks
  7. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 21 Sep 2012 Link to this post

    Well, glad to hear that.

    All the best,
    Tsvetoslav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017