开发者

Issue with jquery #find on partial postback

开发者 https://www.devze.com 2023-01-03 06:37 出处:网络
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.

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 开发者_如何学JAVAclientside 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?


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.


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


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");


jquery needs to rebind events on partial page postback

This will help u..

0

精彩评论

暂无评论...
验证码 换一张
取 消