views:

155

answers:

5

I have a third party component. It is a calendar control. I have a clientside event on it which fires javascript to show a popup menu. I do everything client side so I can use MVC.

dd

   function MouseDown(oDayView, oEvent, element) {

    try {

        e = oEvent.event;

        var rightClick = (e.button == 2);
        if (rightClick) 
        {
            var menu = $find("2_menuSharedCalPopUp");
            menu.showAt(200, 200, e);
        }


    }
    catch (err) {
        alert("MouseDown() err: " + err.description);
    }


}

The javascript fires perfectly withe $find intially.

I have another clientside method which updates the calendar via a partial postback. Once I have done this all subsequent MouseDowns( rightclicks) which use the $find statment error with 'null'.

All similar problems people have out there seem to be around calling javascript after a postback - with solutions being re-registering an event using PageRequestManager or registering a clientside function on the server - et cetera.

However, the event is firing, and the javascript working - it's the reference in the DOM that seems an issue.

Any ideas?

A: 

Do you mean menu = $('#2_menuSharedCalPopUp'); ?

$find is not declared in your function at all.

use of .find() in jQuery is

<div id="parent">
   <div class="child" />
</div>

$('#parent').find('.child'); // useful for cached jQuery objects
Dan Heberden
if that was the case then it wouldn't work the first time? I mean it should be there but it's a mystery as to why it works the first time. :)
griegs
Thanks Dan, but this did work and the use of #find is a simplified code snippet I found elsewhere..
anonymous
A: 

Have you checked the name and id when you return from your partial view call? it may be the id has changed.

if this is the case then give the control a class name of say "MyCalendar" and then use $find(".MyCalendar");

griegs
+1  A: 

I will try to shed some light on this problem:

  1. $find is not a jQuery method although it may look like one. It comes from ASP.NET Ajax and is used to find ASP.NET Ajax components on the client side. It's correct use is without "#" - it needs the ID of the component which is the ClientID server property in most cases.
  2. I think that you are perhaps using a 3rd party component library which is based on ASP.NET Ajax. It is quite possible that this library does not support the MVC way of doing Ajax. MVC Ajax does not work as ASP.NET Ajax - it does not act as an UpdatePanel and does not execute the scripts tags in the partial view. As a result the calendar component is never initialized and $find correctly returns null.

What gives? I suggest you try using jQuery ajax for loading partial views. It correctly executes any embedded JavaScript code and may lead to better results.

korchev
Thanks. You're right - the controls do not explicitly support MVC but I am have had success with far more complicated controls thus far. I have to disable viewstate and only use their (rich) client model as per their direction. They even supply a script manager as an add-on to their base library.
anonymous
Thanks for the explanations regarding the $syntax. I had assumed itwas jquery ;-) I am trying all the suggestions now.
anonymous
We have a winner...thanks guys...just to annoy you though - I did get it working with var menu = $find("<%= menuSharedCalPopUp.ClientID %>");I realise I am mixing my MVC partial postbacks (working sweetly) with ASP NET Ajax syntax...confused - I am...
anonymous
A: 

Thanks to all who contributed. You all helped this time. I'm off to do some more reading.

anonymous