tags:

views:

1253

answers:

6

When I use:

new AjaxOptions { UpdateTargetId = "VoteCount" + indx, OnSuccess = "AnimateVoteMessage" }

everything works fine...but I am trying to animate items in a list, with automatically assigned ID's. Since I want each of these to be addressable from my javascript, I believe I need to pass a parameter to my javascript. But when I use:

new AjaxOptions { UpdateTargetId = "VoteCount" + indx, OnSuccess = "AnimateVoteMessage(2)" }

I get an " Sys.ArgumentUndefinedException: Value cannot be undefined." exception. Well I get that when using the debug versions of MicrosoftMvcAjax.js. When using the compressed version I get a "Microsoft JScript runtime error: 'b' is null or not an object"

So my question is, can I pass a parameter to my javascript function using the OnSuccess event for a ActionLink?

Is this the right approach? How else am I going to have one javascript function have the ability to be run on 10 items (in my case the IDs of multiple DIVs) on my page?

A: 

I ran in this issue too... and did not find a way to solve it! I did a workaround (which is not nice but solved it for now... maybe until someone posts a solution here)... what I did was place a hidden field in the TargetId div and OnSuccess I called a js method which retrieves the value from the hidden field <- this could happen in your AnimateVoteMessage method ...

silverfighter
+1  A: 

Use this:

OnSuccess = "function(){yourfunction(" + productcode + ");}"

or

OnSuccess = "function(){yourfunction(this, " + productcode + ");}"

Fujiy
are you sure that works? I get a syntax error when I click on a link which was built using this technique.
dalbaeb
Show me your code please
Fujiy
i had this exact same problem as described on both 'debug' and 'non debug' versions, with the exact same errors - and tried your method, and it worked for me perfectly. why can't the vs people just tell us to call functions like this if it's so tempremental and picky about a basic function call? bloody idiots, have wasted 4 hours of my time already. but thanks heaps Fujiy and poster of question for resolving yet another senseless vs bug! and to think, i am using vs2010 RTM!!!!
Erx_VB.NExT.Coder
+3  A: 

Try this - it works for me:

OnSuccess = "new Function('MyFunction(" + myParameter + ")')"

Alex42
what you suggested worked perfectly for me, as i had the same problem. thank you.
Erx_VB.NExT.Coder
+5  A: 

or...a bit different syntax that worked for me:

OnSuccess = "( function() { MyFunction(arg1,arg2); } )"

Mike
That works great! Thanks for the tip.
John Nelson
A: 

i have this EXACT same problem and have now wasted 3 hours trying to find a solution. using vs2010 rtm, i can't stand it - if ms can't write bug free code hwo about it stops wasting everyones time or includes proper information on how something is supposed to be used. absolute rubbish.

Erx_VB.NExT.Coder
A: 

See http://www.codeproject.com/KB/ajax/Parameters-OnSuccess.aspx

Basically:

function yourCallBack(arg1,arg2) {
        return function(result) { // Your old function
            alert(arg1);  // param will be accessible here
            alert(arg2);  // param will be accessible here
            alert(result);// result = the response returned from Ajax
        }        
    }
ASP.Net Forum