Any downsides to using ASP.Net AJAX and JQuery together

前端 未结 9 1050
深忆病人
深忆病人 2021-02-04 10:41

We are planning to use the jQuery library to augment our client side JavaScript needs.

Are there any major issues in trying to use both ASP.Net AJAX and jQuery? Both li

相关标签:
9条回答
  • 2021-02-04 11:18

    One downside is that server side controls can get renamed, depending on their containers. For example, you might have:

    <asp:panel id="panel1" runat="server"></asp:panel>
    

    This may be rendered to the page as:

    <div id="ctl00$panel1"></div>
    

    So if you write jQuery using $('#panel1') as a selector, it won't work. The way around this is to generate the id dynamically, eg:

     Dim js as String = "$('" & panel1.ClientID & "').whatever();"
    

    This can make the javascript a bit unreadable, but it does work quite well. I work on a large web app using this method, and jQuery has saved us a TON of time, not to mention making the site look and work much better.

    0 讨论(0)
  • 2021-02-04 11:28

    For what it's worth, there is no conflict between jQuery's $ function and ASP.NET AJAX's $ prefixed shortcut functions ($get, $find, $create, etc). Just the same as using a variable f doesn't prevent you from using a variable named foo.

    jQuery and ASP.NET AJAX work well together in the majority of cases. In the past year, the only time I've seen ASP.NET AJAX break jQuery code was this scenario with jDrawer. The workaround wasn't bad though.

    0 讨论(0)
  • 2021-02-04 11:36

    I've used jQuery with ASP.NET Ajax as they both do different things well. I've never had an issue with using the two together. In fact, I get around the wierd ASP.NET id mishmash by using the super powerful jQuery selectors. By being able to select classes and sub-elements of elements (basically CSS) it makes it very easy to use.

    0 讨论(0)
提交回复
热议问题