Calling codebehind after automatic update

7 posts, 1 answers
  1. Neil N
    Neil N avatar
    89 posts
    Member since:
    Aug 2012

    Posted 06 Jan Link to this post

    How do I execute some server-side code after data has been updated, triggered by the user clicking "Save changes" in an automatic-update batch-editmode grid? I need to manipulate some other controls after a successful update.
  2. Rumen
    Admin
    Rumen avatar
    13927 posts

    Posted 09 Jan Link to this post

    Hi Neil,

    You can use the dedicated BatchEditCommand event handler or the ItemCommand event handler by checking for this condition:

    if (e.CommandName == RadGrid.BatchEditCommandName) { ... }

    Here you are a suitable documentation article Batch Editing Server-side API.

    Best Regards,
    Rumen
    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.
  3. Neil N
    Neil N avatar
    89 posts
    Member since:
    Aug 2012

    Posted 09 Jan in reply to Rumen Link to this post

    Hi Rumen,

    Unless I'm missing something (apologies if I am), neither of these options provides what I asked for.

    Protected Sub grdSalesReport_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles grdSalesReport.ItemCommand fires for every single change. If twenty rows are changed, the event is fired twenty times.

     

    Protected Sub grdSalesReport_BatchEditCommand(sender As Object, e As GridBatchEditingEventArgs) Handles grdSalesReport.BatchEditCommand fires before the update statements are sent to the database. It's an an automatic-update batch-editmode grid as stated above.

    I need to run some code after all the updates have been sent.

  4. Rumen
    Admin
    Rumen avatar
    13927 posts

    Posted 11 Jan Link to this post


    The SqlDataSource control has an OnUpdated event which raises the Updated event after the SqlDataSource control has completed an update operation. You can find more on this at MSDN: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.sqldatasourceview.onupdated?view=netframework-4.7.2.

    Best regards,
    Rumen
    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.
  5. Neil N
    Neil N avatar
    89 posts
    Member since:
    Aug 2012

    Posted 11 Jan in reply to Rumen Link to this post

    Again, I don't think this is what I'm asking for. From the doc:

    Raises the Updated event after the SqlDataSource control has completed an update operation.

    What I asked for:

    I need to run some code after all the updates have been sent.

  6. Answer
    Attila Antal
    Admin
    Attila Antal avatar
    297 posts

    Posted 16 Jan Link to this post

    Hi Neil,

    It has become clear that you would like to use an event that fires only once after all the records have been updated. RadGrid has it's DataBound event which fires only when the data is bound to it. Since editing/inserting/updating items requires the grid to rebind, this event would be the perfect one for your scenario. The only problem is that there is no built-in property or method to understand whether a Batch Editing was done or not, but it's very simple to implement.

    For example, you can use the BatchEditCommand which is fired once before any update. At this point you can set a flag that will indicate the reason for the postback. Once all the Updates are finished, data with the changes will be bound to Grid again and so the DataBound event fires. You can use this event in combination with the Flag you have set earlier to identify whether it was an update or not and run the desired logic.

    bool IsBatchCommand = false;
    // Event raised before an actual Update
    protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
    {
        IsBatchCommand = true;
    }
     
    // Event raised after every update is done and data is re-bound to Grid
    protected void RadGrid1_DataBound(object sender, EventArgs e)
    {
        if (IsBatchCommand)
        {
            Label1.Text += "<br />RadGrid1_DataBound";
        }
    }

    Please let us know if you have any question.

    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.
  7. Neil N
    Neil N avatar
    89 posts
    Member since:
    Aug 2012

    Posted 22 Jan in reply to Attila Antal Link to this post

    This is exactly what I needed.  Thank you very much.
Back to Top