OnClick Event Handlers for Edit and Insert

2 posts, 0 answers
  1. Jeff
    Jeff avatar
    2 posts
    Member since:
    Jun 2019

    Posted 31 Jul Link to this post

    I am using a RadGrid as a tool for searching through a table. The table itself has 30 columns. If I bring it directly into the grid (e.g. select *), its width spans three screens, which is unacceptable to the client.

    So instead of loading the entire table, I've written the grid's select statement to bring in only the 10 most useful columns for searching. I would like to capture something like an OnClick event on the server side that fires immediately after the user clicks on the grid's edit image (the pencil) or insert command link. These events would fire before there is any attempt to bring up a custom edit/insert form or the default in-place form for edits/inserts.

    In that event, I plan to redirect to another page (X) to be used for inserting and updating. Within the event, I would need to know if the edit or insert command had been fired. When editing, I would need to be able to get the record id so I could get all the record's data to display in the edit form. Remember the grid only knows about the 10 columns. I would handle saving back to the DB in X and on success would redirect back to the grid page, which would refresh itself naturally. 

    Is this possible? I can't find anything like OnClick events for edit and insert, and don't know where and how to determine if I'm in Edit or Insert mode, or if in Edit how to find the current record ID.

    Any help would be much appreciated.

  2. Attila Antal
    Admin
    Attila Antal avatar
    386 posts

    Posted 05 Aug Link to this post

    Hi Jeffrey,

    I'll try to quote the requirements from your description and place the answer below it to make it understandable.

    Given the scenario you have described, your first requirement would be:

    "I would like to capture something like an OnClick event on the server side that fires immediately after the user clicks on the grid's edit image (the pencil) or insert command link. These events would fire before there is any attempt to bring up a custom edit/insert form or the default in-place form for edits/inserts."

    Client events cannot be fired on the server, but you can call the Event handler manually if you wish. Although, If using the built-in Edit/Delete Columns, the right event would be the ItemCommand. This event fires before the actions are completed. You can cancel it, if you wish to do something else.

    The following articles will provide you with more information about Commands and methods. You can use a combination of these methods/commands to execute further logic on the server:

    "In that event, I plan to redirect to another page (X) to be used for inserting and updating. Within the event, I would need to know if the edit or insert command had been fired."

    You have access to the event arguments, and there you can understand which commands was fired. Insert/Edit/Delete or even Custom. Make the redirection, or just run other logic.

     

    "When editing, I would need to be able to get the record id so I could get all the record's data to display in the edit form."

    List of articles that will help you access cells, values, controls and more in the grid items:

    Example Running Sample Project with Manual CRUD operations: Update all, individual or selected rows using RadGrid with InPlace edit mode

     

    Everything you have described can be easily achieved. Following the instructions from the links I've shared above, will help you go through and find the way to implement this. Please give it a try, and in let us know if you need further assistance.

     

    Kind regards, Attila Antal
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top