I have a telerik grid that I am using to do a post to the server when the user double click on a row. It appears to work fine until I place an alert in the code and notice some odd behaviors. When I double click on a row for the first time, the alert comes up twice and continues to display twice the number of times that I click. I mean - it comes up twice the first time, 4 times the second time, 6 times the third times, and it continues on. Below is the scripts that I am using to call the grid.

function DisplayStudent(e) {
    if (IsStudentGradeAvailable == "True") {
        $('tr', this).live('dblclick', function () {
            var row = e.row;
            var StudentId= row.cells[0].innerHTML;
            var StudentGrade= row.cells[1].innerHTML;
            var data = { "StudentId= ": StudentId= , "StudentGrade": StudentGrade };
            var url = '@Url.Action("Student", "StudentGrade")';
            $.ajax({
                url: url,
                type: 'post',
                dataType: 'text',
                data: data,
                success: function (data) {
                    alert("Success");
                },
                error: function (error) {
                    alert("Error");
                }

            });
        });
    }
}
有帮助吗?

解决方案

Live attaches an event handler. You want one event handler, so you should call the live() method only once. Given your code, this implies that DisplayStudent() should only be called once.

If DisplayStudent() is called n times, you will have attached n event handlers, each of which alerts you when you click.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top