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

[Solved] OnDelete Client Event Question

4 Answers 268 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
lmf232s
Top achievements
Rank 1
lmf232s asked on 06 Oct 2010, 04:32 PM
I like many others would like to display a message to the user indicating that an action has been performed. You currently expose a couple of different Client Events that we can use to produce such results.

The event in question that Im having issues with is the OnDelete Event. It appears that this event fires regarless of what my selection is on the Delete confirmation popup.

Example: I click the delete button, a popup displays 'are you sure you want to delete this?', I click cancel and the client event OnDelete fires.

This makes sence since the call is OnDelete, meaning this event should fire OnDelete. I suppose what im after is an event more like 'OnDeleted'. An event that I can capture after the delete has successfully been completed.

Any ideas on how i can work around this? Or am I going about this the wrong way?

This is what my code is like:
<%= Html.Telerik().(...).ClientEvents(events => events.OnDelete("onDelete"))%>
<script type="text/javascript">    
    function onDelete(e) {  
        alert("The record has been deleted");
    }
</script>

4 Answers, 1 is accepted

Sort by
0
lmf232s
Top achievements
Rank 1
answered on 06 Oct 2010, 04:47 PM
Just an update to this thread, I suppose what Im really looking for is events that fire after an action has been completed.

I also have an OnSave Client Event. The issue im noticing is that when I click update or insert and for what ever reason an error occures, both the OnSave and OnError events fire. This causes my app to display 2 messages, 1 that says the update was successfull and 1 that says, sorry there was an error.

So it would be nice to see something like

// After Action has been performed
OnSaved
OnDeleted
OnInserted

// Prior to Action
OnSave
OnDelete
OnInsert

I know the OnInsert does not exist but it would be nice to be able to handle things differently depending on if there was an update or an insert performed.

Thanks,
lmf232s


Edit:
I suppose I should of looked at what 'e' has to offer ( function onSave(e) { ). It does appear that you return a mode proper with either 'insert' or 'edit' depending on your action. This allows me to determine if its an insert or an update. Although still need a way to deterimne if the action was successfully completed.
0
Accepted
Atanas Korchev
Telerik team
answered on 06 Oct 2010, 04:59 PM
Hi lmf232s,

Those events fire before the actual operation is completed on purpose. You can cancel most of them by calling e.preventDefault(). However you are right that the OnDelete event should fire only when the user has confirmed the delete. We will look into fixing this for the next release.

Currently it is not possible to tell if an insert has been successful or not because the insert/update occurs server side. That's why we don't have OnSaved, OnDeleted events. You can use the OnDataBound event however - if the grid is bound after insert/update - then it must have completed successfully.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
lmf232s
Top achievements
Rank 1
answered on 06 Oct 2010, 05:25 PM
Thanks Atanas, the OnDataBound event allows me to do what im after.

If anyone comes across this, here is what I whipped up really quick. Ideally I'll use some sort of jquery plugin to display a popup of some sort.
<script type="text/javascript">
    var actionmessage = null;
  
    function onError(e) {
        var errormessage = "There was a problem performing the selected request";
  
        //the current XMLHttpRequest object
        var xhr = e.XMLHttpRequest;
  
        //the text status of the error - 'timeout', 'error' etc.
        var status = e.textStatus;
  
        if (status == 'error') {
            //xhr.status is the HTTP code returned by the server
            if (xhr.status == "404") {
                errormessage = "requested url not found";
            }
            if (xhr.status == "500") {
                errormessage = "The server was unable to process your request.\n" + e.XMLHttpRequest;
            }
        }
  
        alert(errormessage);
    }
  
    function onSave(e) {
        if (e.mode == "edit") {
            actionmessage = "Saved Successfully";
        } else if (e.mode == "insert") {
            actionmessage = "Inserted Successfully";
        }
    }
    function onDelete(e) {
        actionmessage = "Deleted Successfully";
    }
  
    function onDataBound(e) {
        if (actionmessage) {
                alert(actionmessage);
           actionmessage= null;
        }
    }
</script>
0
Frank
Top achievements
Rank 1
answered on 24 Nov 2010, 07:47 PM
Hi Atanas,

I am a bit concerned about your statement here: "However you are right that the OnDelete event should fire only when the user has confirmed the delete. We will look into fixing this for the next release."

How would we be able to provide a custom Delete confirmation message if the event fires after the alert pop-up?

Perhaps the suggestion to extend the API with after-action events (e.g. OnDeleted) might be worth considering.

Thanks for a great set of MVC controls!

Frank.
Tags
Grid
Asked by
lmf232s
Top achievements
Rank 1
Answers by
lmf232s
Top achievements
Rank 1
Atanas Korchev
Telerik team
Frank
Top achievements
Rank 1
Share this question
or