views:

180

answers:

2

this is my function (with other lines ive tried/abandoned)...

function DoClicked(eNumber) {
    //obj.style = 'bgcolor: maroon';
    var eid = 'cat' + eNumber;
    //$get(obj).style.backgroundColor = 'maroon';
    //var nObj = $get(obj);
    var nObj = document.getElementById(eid)

    //alert(nObj.getAttribute("style"));
    nObj.style.backgroundColor = 'Maroon';
    alert(nObj.style.backgroundColor);

    //nObj.setAttribute("style", "backgroundcolor: Maroon");
};

This error keeps getting returned even after the last line in the function runs:

Microsoft JScript runtime error: Sys.ArgumentUndefinedException: Value cannot be undefined.
Parameter name: method

this function is called with an "OnSuccess" set in my Ajax.ActionLink call (ASP.NET MVC)... anyone any ideas on this? i have these referenced... even when i remove the 'debug' versions for normal versions, i still get an error but the error just has much less information and says 'b' is undefined (probably a ms js library internal variable)...

<script src="../../Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcValidation.debug.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>

also, this is how i am calling the actionlink method:

Ajax.ActionLink(item.CategoryName, "SubCategoryList", "Home", New With {.CategoryID = item.CategoryID},
                            New AjaxOptions With {.UpdateTargetId = "SubCat", .HttpMethod = "Post", .OnSuccess = "DoClicked(" & item.CategoryID.ToString & ")"},
                            New With {.id = "cat" & item.CategoryID.ToString})
A: 

I'm guessing something else is bound to a click event, perhaps on the body of the document itself?

Try cancelling the event (you're not passing it in to the function right there, but whatever triggers your click should have access to it).

In jQuery, you want something like:

event.preventDefault();
event.stopPropagation(); // this is the important one

Edit:

You can't just drop them into the function; you'll need to access them according to whatever framework you've got. You're already in a click handler in your code; whatever's triggering that handler should have access to the event object.

For example, in jQuery, you'd do:

$('el').click(function(e){ 
  e.preventDefault(); 
  e.stopPropagation();
  alert('stopped');
});

Edit again:

Is your "DoClicked" method being called from an AJAX callback? That is, it's not a "click" event at all?

Edit again #2:

I'm pretty sure I know what's going on, if not why. It's expecting a function reference in the OnSuccess property, which makes sense. I imagine the function gets called with whatever the response from the POST call is, so something like this would work:

OnSuccess = "DoClicked";

function DoClicked(args){
  // here, args will (maybe? probably?) represent the response from the POST
}
jvenema
i get this error for both of them, running together and seperately: Microsoft JScript runtime error: Object doesn't support this property or method {this is, when i've placed them at the end of the function in question}
Erx_VB.NExT.Coder
hi, DoClicked is called when the ajax operation is finished successfully - so even tho it isnt technically a click event, it functions as one pretty much. however, the problem was solved when i wrapped the DoClicked call inside a function(){...} as per my answer in the 'answer' post on this page. do you any idea on if this is by design or not? because it sometimes works when called plainly (without the wrapping) but in some (this) cases is picky and complains about it - there is no 'correct spec' info on how to do this either, which i find vastly disappointing.
Erx_VB.NExT.Coder
Wow, I've never seen that. It looks like it's expecting a function *reference*, not a function *call*, so something like OnSuccess = "DoClicked" probably would work. In which case, I'm curious what parameters it calls it with...
jvenema
check out my answer/update which worked
Erx_VB.NExT.Coder
A: 

well, this was the answer i subsequently found out:

OnSuccess = "function(){DoClicked(" & item.CategoryID.ToString & ");}"

so, when you call your function via OnSuccess or OnComplete, you just need to wrap it inside a "function() {...}" declaration, and you'll be fine.

Its funny how the vs team doesn't point this out as a 'correct spec' way of doing things, yet it is so picky and ambigious about it when its passed normally. Wasted 4 hours on VS2010 RTM - this is dismal. Surely, this is a bug that they've made no effort to resolve as it's been around for some time now.

Erx_VB.NExT.Coder