views:

192

answers:

2

In my ASP .NET MVC application i have a link that refreshes "the preview data box" after each click. I've done this using this code:

        <%= Ajax.ActionLink("delete", "DeleteItem", new AjaxOptions(){UpdateTargetId="casePreview"}) %>

Now I would like to change the behaviour in such a way that the preview data box is refreshed each time link's onmouseover event is raised.

What's the simplest way to do it?

A: 

Unfortunately there is no way to do this using the AjaxHelpers only: you'll have to use javascript directly. For example, you can use jQuery and "register" to the onmouseover event, and than use the Ajax method to call for the refresh of the "preview data box"

CodeClimber
Can you show me a snippet of code explaining how to do that?
mgamer
+1  A: 

Use jQuery to fire the click event of the link

$(selector).mouseover(function () { 
    $(this).click(); 
});

EDIT: A simplified version of what I described in my comment. Essentially, the mouseover event handler should use some AJAX to retrieve updated information, when the request is complete the UpdateUI function fires and does its work. This particular script would also cause an alert to appear when the element is clicked.

$(selector).mouseover(function() {
    $.ajax({
        type: "GET",
        url: "/my/path/to/someplace",
        complete: UpdateUI});
}).click(function() {
    alert("tada");   
});

function UpdateUI(XMLHttpRequest, textStatus) {
    //Update Your UI
}
Tyler
But what if i need two different behaviours - one for onmouseover event and second one for onclick event?
mgamer
I suggested that above method because it means you wouldn't have to write any extra Javascript. You could handle the mouseover event with an AJAX request and UI update function. That would free up the click event for another behavior.
Tyler