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

Radgrids and edit template resuse

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 17 May 2016, 11:55 AM

We have radgrids with edit templates. In some cases, two different radgrids display records from the same database table. In these cases, the records are editable from either radgrid, so we’re made a user control and placed it in the radgrid’s edit template form. We would also like to display a radalert box if a field if left blank, or contains any other invalid data, and this is where the problem starts.

If the command name of the submit button, located in the user control, is set to “update”, it causes the radgrid’s UpdateCommand event to fire, in the main aspx page. And this event apparently fires before the submit button’s click event fires, and since the radgrid’s UpdateCommand event handler closes the edit template, any attempt to display a radalert from the submit button’s click event fails.

The obvious fix is to not set the command name=update property of the submit button, right? Well, maybe, but if we do that, then the edit template never closes, even after a successful record update. We could try to close the edit template “manually” from the user control’s submit button click event, but we’ve been unable to do that so far, and it’s probably bad design to do anyway.

So, my question is this: What do you recommend as a strategy for “reusing” an edit template between multiple radgrids if you can’t use user controls?

(IIS 7.5, Windows Server 2012, VS 2012, C#, ASP.NET, Telerik runtime version 4.0.30319, IE11, Firefox 45.0)

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 20 May 2016, 08:55 AM
Hello Paul,

Generally, you can use e.Canceled to achieve this validation requirement:
protected void radGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
    // validate custom condition before actual update
    if (true)
    {
        e.Canceled = true;
    }
}
protected void radGrid1_ItemUpdated(object sender, GridUpdatedEventArgs e)
{
    // item was successfully updated
    if (true)
    {
        e.KeepInEditMode = true;
    }
}

You can use asp: RequiredFieldValidator:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-editing/validation#adding-a-validator-explicitly

Or CustomValidator:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator%28v=vs.110%29.aspx

I am also sending a sample RadGrid web site for a practical implementation of both client-side and server-side validation.

I hope this will prove helpful.

Regards,
Eyup
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or