How to maintain input value in edit mode when page partially post back

1 Answer 98 Views
Grid
yuki
Top achievements
Rank 2
Iron
Iron
Iron
yuki asked on 16 Aug 2023, 09:15 AM | edited on 16 Aug 2023, 09:22 AM

Please help.

Hello. I have put a telerik grid inside an asp update panel, the update panel is updated every 5 seconds by a asp timer on the same page. Inside the timer's OnTick event, I wrote RadGrid.Rebind() since the datasource is changing over time.

There is an edit button column for RadGrid, when user presses this button inside this column to edit corresponding record, the input values are always flushed out by RadGrid.Rebind. By the way, the edit mode of grid is in line editing.

In order to handle this issue, I added code inside the timer's OnTick event before RadGrid.Rebind, that is to check if RadGrid.EditItems.Count > 0 then return and don't rebind. Now the input values won't be flushed but the mouse cursor will always be reset.

Is there any possible way to realize my requirement, keep input values in edit mode while the RadGrid is inside an update panel that updates every few seconds?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 21 Aug 2023, 07:28 AM

Hi Yuki,

Since the RadGrid wrapped in an UpdatePanel it will be recreated after each postback triggered by the Timer. With this in mind it is expected that the focus of the last edited item will be lost. The same would normaly happen with the native asp:GridView as well so you may find it useful to research for possible solutions for non Telerik scenarios.

One approach I can think of would be to register a JavaScript code in the OnTick event handler to set the focus to a desired element after the Response of the Postback reaches the Browser:

Additionaly with this approach you will need to keep track of the last focused element on the page (e.g. in a HiddenField) so you can know which element should be focused after the Postback.

Note that this is just an idea you can consider and it is not relevant to any built-in functionality of Telerik Controls.

Alternatively you can think of preventing the Postback of the Timer on the client-side. That way there will be no need for the RadGrid to be rendered anew with the same data. For instance, you can possibly replace the UpdatePanel with RadAjaxManager and cancel its OnRequestStart client-side event when the RadGrid is currenlty being edited:

I hope you will find this information helpful.

Kind regards,
Doncho
Progress Telerik

Heads up! Telerik UI for ASP.NET AJAX versions for .NET 3.5 and 4.0 are retired. Progress will continue shipping assemblies compatible with .NET 4.5 and later. See whether this affects your apps in this article.
yuki
Top achievements
Rank 2
Iron
Iron
Iron
commented on 22 Aug 2023, 06:50 AM

Thank you for the answer! I will try these 2 methods
Tags
Grid
Asked by
yuki
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Doncho
Telerik team
Share this question
or