开发者

ASP.Net Ajax $find() Jquery Equivalent

开发者_开发知识库

Is there a JQuery equivalent of ASP.Net Ajax's $find() function?

$() != $find()


There is not since $find returns the AJAX component related to the DIV element, and not the DOM element. You could build your own plugin that shortcuts the find method.

Microsoft created $find as a way to link their ASP.NET AJAX components to the DOM.


There is not a 1to1 equivalent but what you want is $('selector')

Check out the docs on the different selectors

$find('MyComponent') would be $('#MyComponent')

$find('MyComponent',div) would be $(div).find('#MyComponent')


I'd just do the following, no muss, no fuss, straight to the point.

$('#' + <%=myControl.ClientID%>)


If you want to find an element by its ASP.NET code ID rather than the generated ClientID (ctl00_RealId) then you can use this function. It just looks for elements that have an ID that ends with _{the real ID here}:

var $$ = function (id, context) {
    var $ = (jQuery) ? jQuery : return ;
    var el = $("#" + id, context);
      if (el.length < 1)
        el = $("[id$=_" + id + "]", context);
    return el;
}

For example, say your ID in your code is pnlSuccess, say a panel:

<asp:Panel ID="pnlSuccess" runat="server"></asp:Panel>

But in the rendered code it comes out as: ctl00_content_ctl00_pnlSuccess

calling $$("pnlSuccess") will find that rendered panel.


I know it's a LOOOOOOOONG time overdue, but I think I have the kind of solution you're looking for. If I'm correct, you're looking for a $find jQuery substitute because you don't know the ID of the element (which $find doesn't have selectors as far as I know but jQuery is awesome with). I just ran into this issue using Telerik controls on a SharePoint page, so my object ID is some long crazy mess, and since Sharepoint 2010 is on .NET 3.5, I can't use a static ID.

The solution is simple, but it racked my brain for a while. $find() is searching by ID, which luckily we can return as a string through jQuery: $("elem").attr("id"). So basically what we do is use jQuery inside the $find function and it works. Here's a sample from my project:

var contextMenu = $find($("[id*=mnuContext]").attr("id"));

This worked for me, and is going to help me out a lot with the rest of my SharePoint solution.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜