I'm trying to get on with Script# library and find it challenging to get some jQuery based Ajax code written. Is there any beginner's tutorial or important API documentation that can get me started real quick?
-
Are you already comfortable with jQuery?DuckMaestro– DuckMaestro2011-04-12 22:41:26 +00:00Commented Apr 12, 2011 at 22:41
-
@DuckMaestro: I'm not that comfortable with jQuery and think that C# style coding converted into jQuery would boost my productivity.Suhas– Suhas2011-04-13 05:40:04 +00:00Commented Apr 13, 2011 at 5:40
-
unless you have very strict deadlines or only have a small piece of code to write with no maintenance, you will be better off learning jQuery instead.Raynos– Raynos2011-04-13 10:35:48 +00:00Commented Apr 13, 2011 at 10:35
2 Answers
Since you mentioned you're new to jQuery I would at least start with the jQuery documentation and get comfortable with the basics (see jQuery Documentation).
Once you are comfortable with jQuery, using it in Script# is fairly straight-forward because Script# already includes bindings for jQuery. To get started:
- Make sure you're including jQuery in your HTML page or templates, as you would normally for jQuery (e.g.
<script src="[jQuery]"></script>). - Verify your Script# project has a reference to
Script.jQuery(.dll). - Within your
.cssource file(s) addusing jQueryApi;(for convenience). This is the namespace containing Script#'s jQuery bindings.
Now you can utilize jQuery in your Script# code, in a fashion that maps fairly 1:1 to if you were using jQuery within JavaScript. The biggest difference though is in how you first create a jQuery object.
In JavaScript:
// selector
var paragraphs = $("p");
// ad-hoc html
var someHtml = $("<strong>hello</strong>");
// existing DOM element
var elementFromDom = $(document.getElementById("myDiv"));
// ready callback
$(function() { doSomething(); });
In Script#/C#:
// selector
jQueryObject paragraphs = jQuery.Select("p");
// ad-hoc html
jQueryObject someHtml = jQuery.FromHtml("<strong>hello</strong>");
// existing DOM element
jQueryObject elementFromDom = jQuery.FromElement(Document.GetElementById("myDiv"));
// ready callback
jQuery.OnDocumentReady(delegate { DoSomething(); });
Comments
Recently at MIX11, Nikhil Kothari, the creator of Script# delivered a very good session on Script# followed by a nice blog post covering how to use Script# with jQuery. This is perfect for the beginners. Below are the links for the video of the session and the followed blog post
video - http://channel9.msdn.com/Events/MIX/MIX11/HTM16
archived blog post - http://web.archive.org/web/20110421060154/http://www.nikhilk.net/ScriptSharp-MIX11.aspx