Radgrids and edit template resuse

2 posts, 0 answers
  1. Paul
    Paul avatar
    16 posts
    Member since:
    Feb 2016

    Posted 17 May Link to this post

    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)

  2. Eyup
    Eyup avatar
    2941 posts

    Posted 20 May Link to this post

    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:

    Or CustomValidator:

    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.

    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. DevCraft R3 2016 release webinar banner
Back to Top