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

Cancel Rad Grid PageSizeChanged Event

12 Answers 165 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Parag
Top achievements
Rank 1
Parag asked on 01 Feb 2013, 07:10 AM
Hello,

i cancelled Rad Grid Filter, Sort, PageIndexChanged events in 'ItemCommand' event (e.Canceled= true). But i unable to cancelled PageSizeChanged event. How can i achieve this?

12 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Feb 2013, 08:43 AM
Hi,

Please try the following code snippet to cancel the PageSizeChanged event in ItemCommand.

C#:
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{     
    if (((System.Web.UI.WebControls.CommandEventArgs)(e)).CommandName == "ChangePageSize")
    {
        e.Canceled = true;
    }   
}

Thanks,
Princy.
0
Parag
Top achievements
Rank 1
answered on 01 Feb 2013, 09:17 AM
Princy, thanks for quick reply, but did not work. When i changed PageSize still NeedDataSource event fires
0
Eyup
Telerik team
answered on 06 Feb 2013, 09:49 AM
Hi Parag,

This command will cause an internal rebind operation. Can you please elaborate some more on your specific scenario? This will help us to figure out your exact requirements and suggest a proper approach.

Kind regards,
Eyup
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.
0
Parag
Top achievements
Rank 1
answered on 07 Feb 2013, 01:40 PM
Hi Eyup,

Thanks for reply.

I have to cancel PageSize event before it takes an effect. I want to handle this event internally, When user changed page size, i have to check some validation when event fire. If validation passes, then it's execution will  continue other wise it cancelled & validation message will display to user.
 i.e.

On PageSize_Event()
{
if(validation is true)
{
//continue page size change event
}
else
{
//display validation & cancel page size event, store changed page size into ViewState
//reset page size to it's original value
}
}
0
Eyup
Telerik team
answered on 12 Feb 2013, 01:33 PM
Hello Parag,

You can use the following approach:
protected void grid_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
{
    if (false) // validation condition
    {
        // continue
    }
    else
    {
        e.Canceled = true;
    }
}

That should do the trick. Please give it a try and let me know about the result.

Please note that NeedDataSource event will still fire since canceling the event requires rebinding the grid to reset the grid to its initial state.

All the best,
Eyup
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.
0
Parag
Top achievements
Rank 1
answered on 13 Feb 2013, 04:58 AM
Hello Eyup,

Yes, your last post works fine. It cancel Page Size Event. As you mention, still it fires NeedDataSource, can you find some work around for the same. Any ways i don't want to rebind grid (this is achieved in case of Sorting, Filtering event) , because i have to persist data in grid controls if user has changed some thing.

eagerly waiting for reply...

Thanks,
Parag
0
Eyup
Telerik team
answered on 18 Feb 2013, 09:01 AM
Hi Parag,

Currently, this can be only achieved if you overwrite the client side command to cancel the server side execution. Is this applicable for your requirements?

All the best,
Eyup
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.
0
Parag
Top achievements
Rank 1
answered on 18 Feb 2013, 09:28 AM
Hi Eyup,

I can not use client side code to cancel PageIndexChanged event (i.e. NeedDataSource event) of rad grid, cause i have to perform some actions on server side.

Is there any other way?

Thanks,
Patag
0
Eyup
Telerik team
answered on 21 Feb 2013, 02:13 PM
Hi Parag,

Please try the following approach:
JavaScript:
<script type="text/javascript">
    Telerik.Web.UI.GridTableView.prototype.set_pageSize = function (value) {
        if (this.PageSize != value) {
            this.PageSize = value;
            this.set_currentPageIndex(0, true);
            this.fireCommand("PageSizeChangeInitiated", value);
            this._updatePager();
        }
    }
</script>
C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "PageSizeChangeInitiated")
    {
        if (false) // custom condition
        {
            e.Item.OwnerTableView.PageSize = int.Parse(e.CommandArgument.ToString());
            e.Item.OwnerTableView.Rebind();
        }
    }
}

That should do the trick. Please give it a try and let me know if it works for you.

All the best,
Eyup
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.
0
Kim
Top achievements
Rank 1
answered on 24 Mar 2014, 10:33 PM
Hi,

I know this is an older thread, and the suggested solution works great.

But I have one problem.  The new value in the Page Size Combo box that was selected by the user still shows the new value, even though it failed my audit.

That is, it was originally 10, the user selected 20.
Since it failed the audit I would like to make sure it gets set back to 10.
But at the _ItemCommand event the page size values still show 10, so resetting it to 10 is doing nothing.
Should I be catching an event somewhere to make sure the 20 is not selected.

Thanks.

Kim
0
Kim
Top achievements
Rank 1
answered on 26 Mar 2014, 04:42 PM
Hi,

Another issue.   I have more than one telerik grid on my page, let's say RadGrid1 and RadGrid2.

I only want RadGrid1 to use the special Page Size functionality:  Telerik.Web.UI.GridTableView.prototype.set_pageSize

How can I make just RadGrid1 use the set_pageSize.  Right now RadGrid2 is hitting the javascript logic for the set_pageSize and it shouldn't.

Thanks.
0
Eyup
Telerik team
answered on 27 Mar 2014, 03:48 PM
Hi Kim,

I have created a sample RadGrid web site to demonstrate how you can achieve the requested functionality. Please run the attached application and let me know if it helps you.

Regards,
Eyup
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
Grid
Asked by
Parag
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Parag
Top achievements
Rank 1
Eyup
Telerik team
Kim
Top achievements
Rank 1
Share this question
or