Archive: January, 2010

Impulse Studio Labs has produced the first cheat sheet I’ve found for the new version of jQuery. It’s printer-friendly, fits on one page, marks all the new or changed functions and I don’t think they missed anything important.
One of the most annoying “features” of the current .Net versions is the automatic generation of the ids for server controls. I’m doing a lot of my work with JavaScript and especially with jQuery, so these unpredictable ids make the selection of elements not only difficult, but also really slow.
Most of the time it’s pretty easy to avoid server controls, but if you want to relay information from the server to the client at startup, you are usually stuck with WebControls like Literals or HTML controls for hidden fields.
At least that was what I thought till I stumbled upon a command to create hidden fields without these horrible long ids in a separate div container right after the form tag:
ClientScript.RegisterHiddenField(string id, string value)
I usually create my fields in Page_Load like this:
using System.Web.UI; ... protected override void Page_Load(){ ClientScriptManager csm = Page.ClientScript; csm.RegisterHiddenField("foo", "1"); csm.RegisterHiddenField("bar", string.Empty); }
This will create the following HTML code:
<form ...> ... <div> <input type="hidden" id="foo" name="foo" value="1" /> <input type="hidden" id="bar" name="bar" /> </div> ... </form>
Of course you won’t be able to read or manipulate the field later like a WebControl. And you have no control about the final placement on the page either. But that was never my intention and you can do whatever you want with the field in your JavaScript anyway.
I’ve been eagerly waiting for the next update on my favorite JavaScript library, jQuery. I haven’t done any testing, but the list of new features looks very promising:
- Major performance boost for often used functions like
.html(),.remove()or.find(). - You can pass functions now into even more setter functions and their return value will be added to the appropriate attribute.
- Many improvements in handling Ajax calls like support for Etags or auto-detection of
content-type. - Quick element construction similar to
dojo.create. - New events, focusin and
focusout, and a new functionjQuery.proxy()that makes handling this in events easier. - Many many more…