views:

45

answers:

1

Hello,

I have a scenario where the ajax actionlink text is 'Apply'..On clicking this and calling an action, i want the link to be disabled and to be changed to 'Application successful'.

How can i do this?

Thanks

A: 

You could use OnSuccess:

<%= Ajax.ActionLink("Apply", "Apply", new AjaxOptions { 
    OnSuccess = "myCallback"
}) %>

and then implement the function:

function myCallback() {
    this.innerHTML = 'Application successful';
    this.onclick = function () {
        alert('Already done');
        return false;
    };
}

By the way is there any reason for using the intrusive MS AJAX instead of jquery and normal Html.ActionLink:

<%= Html.ActionLink("Apply", "Apply", null, new { id = "apply" }) %>

And then in a separate js:

$(function () {
    $('#apply').click(function () {
        var a = $(this);
        $.get(this.href, function () {
            a.text('Application successful').unbind('click').click(function () {
                alert('Already done');
                return false;
            });
        });
        return false;
    });
});
Darin Dimitrov
thanks..can i pass multiple parameters in html.actionlink?
femi
Yes you can pass multiple parameters: `<%= Html.ActionLink("Apply", "Apply", null, new { id = "apply", param1 = "value1", param2 = "value2" }) %>`.
Darin Dimitrov