This is a migrated thread and some comments may be shown as answers.
mvc grid - Preventing multiple insert button clicks
1 Answer 23 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
bradley
Top achievements
Rank 1
bradley asked on 13 Oct 2011, 04:49 AM
Hi,

I have recently come across an issue with the inline insert on my mvc grid and was wondering if i could get a little guidance?
 
After I have filled out all the required data, if the insert button is clicked multiple times in quick succession the insert event fires more than once, generating multiple identical records.

I thought that I may have been doing something wrong, but then I checked on the telerik demo page and found that this behavior exists in the demo... http://demos.telerik.com/aspnet-mvc/grid/editingajax

Is there any known way to ensure that this button only process the first click event?

Cheers,
Brad.

1 Answer, 1 is accepted

Sort by
0
Dave
Top achievements
Rank 1
answered on 12 Jan 2012, 09:39 AM
Telerik stuff is currently broken in this regard. However, with a little jQuery, you can do:

function showFakeButtons(HostGridID) {
// generates fake buttons to mimick those of telerik
    var toolbarSelector = "#" + HostGridID + " > .t-toolbar";
    if ($(".fake-telerik").length == 0) {
        $(toolbarSelector).children().each(function () {
            $(toolbarSelector).append($(this).clone().addClass("fake-telerik").css("opacity", "0.5").css("pointer","not-allowed"));
        });
    }
    $(toolbarSelector).children().each(function () {
        if (!$(this).hasClass("fake-telerik")) {
            $(this).hide();
        } else {
            $(this).show();
        }
    });
}


function showRealButtons(HostGridID) {
    var toolbarSelector = "#" + HostGridID + " > .t-toolbar";
    $(toolbarSelector).children().each(function () {
        if ($(this).hasClass("fake-telerik")) {
            $(this).hide();
        } else {
            $(this).show();
        }
    });
}

// attach this to your grid's OnSubmit event
function onGridSubmit(e) {
    showFakeButtons("Put_Your_Grid_ID_Here");
}

// attach this to your grids OnComplete event
function onGridComplete(e) {
    showRealButtons("Put_Your_Grid_ID_Here");
}

//--
Here's hoping someone at Telerik fixes this. It's well broken.
Tags
Grid
Asked by
bradley
Top achievements
Rank 1
Answers by
Dave
Top achievements
Rank 1
Share this question
or