Thursday, April 10, 2008
Milos Web Development supports jQuery
Have you ever used jQuery? (www.jQuery.com). It is a very cool JavaScript library that makes all kinds of client-side HTML development much easier. The most recent version of Milos web control (ASP.NET) now use jQuery for internal stuff and it is also available for you to use in your own client-side efforts. Whenever you include SimpleWebControls.dll in one of your projects, you automatically get access to jQuery stuff. All you have to do is include a script reference, as well as the Milos resource HTTP handler in the web.config (which you should always have anyway). So the web.config needs to have this:
<
httpHandlers>
<!-- Other stuff here... -->
<add verb="*" path="Milos_simplewebcontrols_*.aspx"
type="EPS.Web.SimpleControls.ResourceRequestHandler,
SimpleWebControls"/>
</httpHandlers>
With this in place, you can simply add a <script> element to your page to get the jQuery features:
<script
src="milos_simplewebcontrols_getresource.aspx?resourcetype=Script&resourcename=JQuery"
type="text/javascript"></script>
Note: This aspx page does not really exist. Whenever this URL gets hit, Milos intercepts the call and returns a dynamically generated script stream to the client.
With this in place, you can now add jQuery stuff like this:
$(document).ready(function() {
alert("Main document content loaded!");
});
For more information on jQuery syntax and features, visit www.jscript.com, or get one of the many jQuery books out there (the jQuery site lists several).
Note: Milos also uses jQuery features for some of its advanced scripting. For this reason, it could happen that the script reference gets included multiple times, which could lead to unexpected results. For that reason it is better to add the script reference in the Load() event of the page (or a control) using this code:
if (!Page.ClientScript.IsClientScriptIncludeRegistered("JQuery"))
{
page.ClientScript.RegisterClientScriptInclude("JQuery",
"milos_simplewebcontrols_getresource.aspx?resourcetype=Script&resourcename=JQuery");
}
This automatically adds the script reference from above, but it only adds it if the reference isn't there already.
There is a lot of cool stuff that can be done with jQuery, from simplified event handling to relatively advanced (for HTML) visual effects. Milos uses this for a number of things, such as the cool new overlay dialogs. But that is a topic of a different post... :-)
Posted @ 1:03 PM by Egger, Markus (markus@code-magazine.com)
Post a Comment:
Comment Title (required):
Your Name (optional):
Your Email (optional):
Your Web Site (optional):
Your Comment (required):