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

ItemCreated event trigger

2 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Larry
Top achievements
Rank 1
Larry asked on 17 Jul 2014, 07:14 PM
I need to know if there is a way to determine what is triggering my ItemCreated event when I have a GridEditableItem in edit mode and the user is clicking the "Update" button, "cancel Button" or neither.  On my page, the itemCreated event is being triggered when the user clicks the update or cancel button when my GridEditableItem is in editmode.  This is fine.  However, the event is also triggered if another control on my page is clicked while my GridEditableItem is in edit mode and it's click event forces a page load.  If this happens, I could run into a situation where my grid row is open for update/cancel, a new page is loaded and my grid row remains open for update/cancel after the page has been refreshed (which I do not want). I want to force "cancel" the edit mode when this happens, before the page is refreshed.   Since I'm able to capture the logical flow of activity in the ItemCreatedEvent when the user does something on my page that is outside of the update/cancel activity of my row, I need to be able to determine what type of activity is firing off the ItemCreated event (update/cancel or neither) in order to assess whether to manually kick off the cancel event through the item's FireCommand method or not.  Is there a way to do this?

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 18 Jul 2014, 09:52 AM
Hi Larry,

You can use the OnItemCommand event to identify the command raised.

C#:
bool isUpdate = false, isCancel=false;
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (isUpdate )
    {
      //Your Code
    }
    if (isCancel)
    {
      //Your Code
    }
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.UpdateCommandName)
    {
        isUpdate = true;
    }
    else if (e.CommandName == RadGrid.CancelCommandName)
    {
        isCancel = true;           
    }
}

Thanks,
Princy
0
Larry
Top achievements
Rank 1
answered on 18 Jul 2014, 02:44 PM
Thanks Princy for the response.  It looks like the grid's ItemCreated event gets fired off before it's ItemCommand event, so this example didn't solve my problem.  However, your suggestion did spur the idea that I could use the  page's ItemCommand event in a similar fashion so that I could use the grid's FireCommand method to cancel the edit window when needed.  Thanks again for your help!
Tags
Grid
Asked by
Larry
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Larry
Top achievements
Rank 1
Share this question
or