Posts

Showing posts from 2010

Moving on to Silverlight...

As much fun as it has been to code almost exlusively in ASP.NET with jQuery, I'm moving on to Silverlight 4.  I've actually be working almost exclusively in Silverlight for the past 2 - 3 months, and I love it!  We are using the MVVM design pattern with Prism.  MVVM and Prism (or another IOC) with Silverlight/WPF are an absolute must for complex business apps.  I don't think I have ever absorbed new technology like I have with Silverlight.  Delicious. Anyways, my next several posts will be focusing on Silverlight, with many MVVM-focused posts, and some other stuff as they come (learning and mastering SQL is a lifelong process apparently...) like: Stackpanel with Image size gotcha Mouse event commanding in Silverlight Creating custom attached properties and binding them to your viewmodel Popup and childwindows in Silverlight w/ MVVM - my own take on this subject A good case for temp tables over table variables in MSSQL Lots of fun stuff here, and more to come!

The hidden workings of __doPostBack - Full or Partial Postback?

In experimenting with how I could manually create a partial postback, I ran into some odd behavior.  I was using the old '__doPostBack('target', 'argument')' javascript call to perform the post back and that was all well and good, but I noticed that my page was doing a full post back instead of a partial each time. After digging around for a bit (where would software development be w/o Google search?), I found this tidbit here (I'm always grateful when others have spent a few hours finding little programming nuggets to share - less time searching for me): __doPostBack starts by trying to retrieve an element in the client DOM with the corresponding ClientID to the UniqueID you pass as the first argument to __doPostBack. (it translates the UniqueID to a ClientID by replacing the "$"s in the UniqueID with "_"s) If it finds a corresponding client element, it searches up the DOM for a parent that has the same id as an updatepanel (it kee

Unobtrusively change/wrap the onclick event handler in jQuery

In designing a user control that does quite a bit of UI manipulation to an ASP.NET page on the client-side of things, I ran into a bit of trouble in using a 'wrapper' onclick handler for a GridView row onclick event.  I will be putting this user control on many pages and did not want to couple the control to the page, or at least I wanted to minimize that coupling as much as possible. Ultimately, I was left with two choices:  manually change the server-side injected javascript for the row's onclick event on every page, or find a way to do it in the user control.  The user control uses the jQuery library, so I was in luck.  When I say I want it to be unobtrusive, I mean I want to execute whatever code the row's event handler has been coded to execute, but under the inspection of my user control (i.e. - to only do so conditionally). My user control injects a new column into the GridView when a certain mode is introduced, which column is purely independent of the rest

Quick rendering of modified ASP.NET GridView w/ some jQuery magic

I came across a powerful performance saver using jquery while adding a column to an Asp.Net GridView client-side.  Put very simply, when creating the columns (including the header), set the display to "none".  Group the new header column and each new row's column with a special css class (like "somethingfunkythiswaycomes"). When all the rows have been changed (at the end of your .each jquery loop), simple call: $(".somethingfunkythiswaycomes").show(); In firefox and chrome, the rendering is very fast and the whole action is at least as fast as a partial postback, w/o any annoying flicker. NOTE :  In IE (which continues to stand tall as the world's worst browser - maybe IE 9 will change my mind...), this technique does NOT work.  When I tried to use this on a 1000 row result set, it took 20 minutes to re-render.  20 freakin' minutes!?  Are you insane??  In Firefox 3 and Chrome 4, it took maybe 2 - 3 seconds! Could be another case of Mi

Microsoft vs Microsoft: C# DateTime vs IE 8 Date Object

There's a lot that can be said about what happens to a software corporation once it becomes very large, and one negative aspect is that your products eventually become disconnected.  This is an inevitability, because in order for any specific product to be effective and accepted in the mass markets, it has to be tailored to the people that use them.  What you end up with is a bunch of software products each targeting disparate markets, all part of a suite of very specialized tools. That being said, I think Microsoft's development of and complete move to the .NET framework helps to resolve a lot of these issues for code development.  I would even bet that the main reason they initially researched the development of the .NET framework is because they knew they needed a solid, easy-to-use code base for all of their projects that would drastically ease interoperability, speed development, and improve general code stability for their products.  The natural side-effect of this is th

Convert serialzed JSON date string to a Javascript Date() object

When an DateTime object in C# is converted into a JSON serialized object for a web page, the format of the string looks like this in the JSON object: /Date( )/ See this for more details on why this format was chosen. This is all well and good, but how do you use that? A similar question and answer can be found here , but the solution posted there misses the possibility of a negative int. To expand just a bit on the solution posted there, we'll account for negative numbers: var someDate = new Date(+jsonDate.replace(/\/Date\((-?\d+)\)\//gi, "$1")); The three key things to note here are: 1. This method does not use eval(). eval can be a very dangerous thing to use since it will execute any javascript, so generally we try to avoid using it altogether. This is why we use JSON.parse, for example, instead of eval. 2. The "+" operator is a type converter in javascript that converts the string to an int. 3. The "-?" because the date value c

Cascading DropDowns w/ JQuery ViewState Problem - use the UpdatePanel w/ triggers instead

I spent a lot of time trying to resolve a DOM issue I was having with a cascading drop downs setup on my page.  After mucking around with it for quite a while, I was able to figure out that it wasn't a direct effect of my code, but seemed to be a result of some DOM corruption that was happening from a plugin I was using or something else (that would be very time consuming to uncover). I was making a web service (POST) call to update the 2nd drop down list... if ($(someDDObject).val().length > 0) { someGlobalVariable = $(someDDObject).val(); ExecuteCallback('DoneChanged|' + someGlobalVariable); } The ExecuteCallBack is tied to a server-side async, non-static function that would parse the input and return the updates. A nice clean way to get server-side data without a postback, right? Right...mostly. The problem came in trying to update the client side data. In the callback function on the client, I would process the data like so: function CallBackResul

IE8 Developer Toolbar is in the taskbar but cannot be seen/moved?

I scoured the internet for the solution to this problem and eventually wound up in the registry after I found a tip for a related problem. If you hit F12 and can not see the developer tools window, although you can see it in the taskbar, do the following: 1. Make sure IE 8 is not running. 2. Using regedit, go to HKCU/Software/Microsoft/Internet Explorer/IEDevTools and delete the 'Windows Position' key. 3. Restart IE 8 and hit F12. No restart of your computer is required and reinstalling IE 8 alone will not fix this issue. Voila!