I watched a pdc session by Stephen Walther and in the presentation he was referencing the JQuery js file like the following:
<asp:ScriptManager id="sm1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Scripts/JQuery.js" />
</Scripts>
</asp:ScriptManager>
Is there a advantage or disadvantage to doing it the above way instead of just using a link in the head section of the page.
He was also putting the following into the javascript section of his sample pages to run JQuery:
<script type="text/javascript">
function pageLoad()
{
$(":text").css("background-color","yellow");
}
</script>
Is the pageLoad necesary above? He mentioned that it is from the Microsoft AJAX library and it waits for the DOM to be finished loading, but I thought the $ symbol in JQuery is just a shorthand for waiting for the DOM to be finished loading.
JQuery is a JavaScript library. It is helpful and make easy to handle HTML DOM (Document Object Model), Events and Animation and Ajax functionalities. JQuery reduce code compared to JavaScript. Mostly we use JQuery or JavaScript for client side activities and make Ajax call to ASP.NET Web form/mvc, Web service and WCF.
It is common to see jQuery programs call $(document) or $(this) , for example. jQuery objects can represent more than one element in a document, and you can also pass an array of elements to $() . In this case, the returned jQuery object represents the set of elements in your array.
$(document).ready() and pageLoad() are not the same!
http://encosia.com/2009/03/25/document-ready-and-pageload-are-not-the-same/
From the article:
pageLoad() is called just after the DOM has finished loading. this isn’t the only point at which pageLoad() is called though: It is also called after every partial postback.
In the case of initialization code that should run once, $(document).ready() is the ideal solution.
Using the ScriptManager, ASP.NET can create a single Composite Script to reduce the number of browser requests, and also if the browser supports it, compress the script.
<asp:ScriptManager ID="ScriptManager1" runat="server">
<CompositeScript>
<Scripts>
<asp:ScriptReference Path="~/Scripts/Script1.js" />
<asp:ScriptReference Path="~/Scripts/Script2.js" />
<asp:ScriptReference Path="~/Scripts/Script3.js" />
</Scripts>
</CompositeScript>
</asp:ScriptManager>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With