javascriptajaxvb.netpaginationtelerik

Dont paging in telerik control in vb.net


I have a reference project code by VB and using telerik .NET UI control. But it have a problem in paging. This is my Employee page, it has been divided into pages but when i click on the other page (eg. 2), the data on table only show data in page 1, i set pagesize 10 is DefaultPageSize (there are 18 items in 2 pages).

Public Overrides Sub ViewLoad(ByVal e As System.EventArgs)
    Try
        SetGridFilter(rgEmployee)
        Refresh()
        UpdateControlState()
    Catch ex As Exception
        DisplayException(Me.ViewName, Me.ID, ex)
    End Try
End Sub

Public Overrides Sub ViewInit(ByVal e As System.EventArgs)
    rgEmployee.AllowCustomPaging = True
    rgEmployee.PageSize = Common.Common.DefaultPageSize
    'rgEmployee.ClientSettings.EnablePostBackOnRowClick = True
    InitControl()
End Sub

Protected Sub InitControl()
    Try
        Me.ctrlMessageBox.Listener = Me
        Me.MainToolBar = tbarLocations
        Common.Common.BuildToolbar(Me.MainToolBar, ToolbarItem.Create,
                                   ToolbarItem.Edit,ToolbarItem.Save, 
                                   ToolbarItem.Cancel)
        CType(MainToolBar.Items(3), RadToolBarButton).CausesValidation = True
        CType(Me.MainToolBar.Items(3), RadToolBarButton).Enabled = False
        CType(Me.MainToolBar.Items(4), RadToolBarButton).Enabled = False
        Me.MainToolBar.OnClientButtonClicking = "OnClientButtonClicking"
        'CType(Me.Page, AjaxPage).AjaxManager.ClientEvents.OnRequestStart = "onRequestStart"
    Catch ex As Exception
        DisplayException(Me.ViewName, Me.ID, ex)
    End Try
End Sub

in refresh() function call rgEmployee.Rebind() and the html

<tlk:RadPane ID="RadPane3" runat="server" Scrolling="None">
        <tlk:RadGrid ID="rgEmployee" runat="server" Height="100%">
            <MasterTableView DataKeyNames="ID" ClientDataKeyNames="CODE, EMP_NAME, EMP_AD">
                <Columns>
                            <%--<tlk:GridClientSelectColumn> here --%>
                </Columns>
            </MasterTableView>
        </tlk:RadGrid>
        <Common:ctrlMessageBox ID="ctrlMessageBox" runat="server" />

    </tlk:RadPane>

<script type="text/javascript">
    var enableAjax = true;

    function onRequestStart(sender, eventArgs) {
        eventArgs.set_enableAjax(enableAjax);
        enableAjax = true;
    }
</script>

As i mentioned before, this is a reference project so i refer to the other pages which were paging successful, is different in the "CType(Me.Page, AjaxPage).AjaxManager.ClientEvents.OnRequestStart = "onRequestStart"" call javascript at HTML (slightly silly b/c i really don't know much more about telerik control and this is alse the first time i look at vb code so i can't understand well). I added this code into employee codebehind. It event don't show any things avoid the things from masterpage. Does the problem is there?

When i change rgEmployee.PageSize=20 (don't have "CType(Me.Page, AjaxPage).AjaxManager.ClientEvents.OnRequestStart = "onRequestStart""), it shows all data correctly, and chosing pagesize=10 (were supported by radgrid), it showed correctly too into 10 items for each page (i mean page 2 show 8 items)


Solution

  • You appear to be performing changes on every time the page is posted to this is not recommended and can sometimes cause very peculiar behavior.

    Example:

    Public Overrides Sub ViewLoad(ByVal e As System.EventArgs)
        If(Not IsPostBack) Then ' You should only 
            Try
                SetGridFilter(rgEmployee)
                Refresh()
                UpdateControlState()
            Catch ex As Exception
                DisplayException(Me.ViewName, Me.ID, ex)
            End Try
        End If
    End Sub
    

    You might find the following question useful in explaining why: Implementation of IsPostBack in page load