Tuesday, November 22, 2011

Developing for a specific version of Silverlight

I recently ran into an issue where the version of Silverlight I had installed on my development environment didn’t match my end clients’ version of Silverlight.

I was running Silverlight v4.0.60831.0, they were running Silverlight v4.0.50401.0. (Who would of thought a 0.0.1 difference would of really mattered?)

Anyway I set out to accomplish two tasks

  1. Replicate the issue by uninstalling my version of Silverlight and installing there’s.
  2. Update my development environment so that I could fix the problem.

Here are my notes:

I using Control Panel to Uninstall Silverlight 4 from my test box.

I located an older version of Silverlight by using Microsoft’s “Microsoft® Silverlight™ Release History.” Which I installed on my test box.

I successfully reproduced the error.

I used Control Panel to Uninstall Silverlight 4 SDK from my development box.

I downloaded the SDK for the specific version I needed. Once again, using Microsoft’s “Microsoft® Silverlight™ Release History.” Which I installed on my development box.

I opened Visual Studio 2010, rebuilt the solution, deployed, the error was corrected.

That’s it. I hope it helps someone.

Wednesday, July 6, 2011

Making the selected time of a RadTimePicker scroll to top.

I rely heavily on Telerik’s ASP.NET AJAX tools. Recently I had an issue with the RadTimePicker when we attempted to put it in a scrolling container. Once in the container could scroll we wanted the selected time to be the first item when the picker’s TimeView appeared.

Out of the box this behavior is not possible, so I had to find a solution. After a lot of research, and some help from Telerik, I would like to share my solution:

To allow for scrolling you have to apply the proper styles

   1: <style type="text/css">
   2:     #<%= StartTime.ClientID %>_timeView_wrapper {
   3:             overflow:auto;
   4:             width:83px;
   5:             height:200px;
   6:     }
   7: </style>

The RadTimePicker

   1: <telerik:RadTimePicker runat="server" ID="StartTime" CssClass="rsAdvTimePicker"
   2:     Width="78px">
   3:     <dateinput id="DateInput3" runat="server" emptymessagestyle-cssclass="riError" emptymessage=" " />
   4:     <timepopupbutton visible="false" />
   5:     <timeview id="TimeView1" runat="server" columns="1" showheader="false" starttime="00:00"
   6:         endtime="23:59" interval="00:30" />                                                        
   7:     <ClientEvents OnPopupOpening="InitializePopup" />
   8:     <ShowAnimation Duration="0" />
   9:     <HideAnimation Duration="0" />
  10: </telerik:RadTimePicker>

Lastly, I used a bit of JavaScript and jQuery to apply the “scroll to top” behavior.

   1: <script type="text/javascript">
   2:     function InitializePopup(sender, eventArgs) {
   3:         var htmlPopUp = eventArgs.get_popupControl().get_element();
   4:         var jQueryPopUp = $(htmlPopUp);
   6:         setTimeout(
   7:         function() {
   8:             var selectedTime = jQueryPopUp.find(".rcSelected");
  10:             if (selectedTime.length > 0) {                    
  11:                 selectedTime.get(0).scrollIntoView(true);
  12:             }
  13:         }, 150);
  14:     }        
  15: </script>

You’ll notice I set a delay on line 6. This is because the TimeView html object needs a bit of time to render before we preform the find. Without this delay, the find returns an empty collection, and the scroll will not work.

I hope this helps someone.


Wednesday, June 22, 2011

Grok talk on NuGet 6/22/2011 1800 EST

I will be giving a grok talk about “NuGet” (the Visual Studio 2010 extension) to the Dayton .NET Developers Group. If you’re in area, I invite you to come down. (Don’t forget to point and laugh Winking smile)

Here is my slide deck.

When: June 22, 2011 at 6pm EST

Where: 711 East Monument Avenue, Suite 101 in downtown Dayton, OH

Wednesday, May 18, 2011

jQuery Boxy content will not display / show

Every so often I’ve used the jQuery plugin called “Boxy

Today I ran into an issue: The content I gave boxy would not display / show on the page.

Here was my incorrect code:

   1: new Boxy("Justin Kohnen is the best programmer ever!", 
   2: { 
   3:     closeText: "close"
   4:     , title: "Shout out."
   5:     , unloadOnHide: true
   6: });

After reading the fantastic manual I found: (underline added for emphasis)

The content passed to the constructor can be any valid parameter to jQuery's $() function - a DOM element, an HTML fragment or another jQuery object. Whatever is provided will be set to display: block and have the class boxy-content added prior to its insertion within the dialog.

The key here was raw text is not a “valid parameter to jQuery’s $() function.”

So my fix is simply to wrap my text in a <p> tag. Making it an HTML fragment

Here is the corrected code:

   1: new Boxy("<p>Justin Kohnen is the best programmer ever!</p>", 
   2: { 
   3:     closeText: "close"
   4:     , title: "Shout out."
   5:     , unloadOnHide: true
   6: });

Simple, but silly problem.

I hope this helps someone.


Tuesday, April 12, 2011

Installing and Uninstalling a Windows Service from the Command Line

I develop a windows service every now and then. I always have to dig up the install and uninstall commands. I figured I would post it for all.


C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil /LogToConsole=true "<path_to_service_exe>"


C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil /u "<path_to_service_exe>"

Make sure to replace <path_to_service_exe> with what works for you.

If you’re on Win7 or Win2008 Server, you’ll need to start your Command Prompt as an administrator.


Thursday, March 3, 2011

Tracking a browser’s Time zone Offset in ASP.NET

Just the other day I was required to display a website’s dates in a user’s local time.

The solution I came up with was based on getting the time zone offset from the user’s browser using JavaScript, Storing that value into a cookie, then converting the cookie value to the a number I’m used to working with (i.e. negative hours), then I can convert UTC dates to the user’s local time zone by adding the Offset.

All of this magic happens for me in my website’s base page. (All my pages inherit from my base page)

   1: public class BasePage : System.Web.UI.Page
   2: {
   3:     private const string mTimeZoneCookieName = "TZOS"; // Time zone Offset
   5:     protected override void OnPreInit(EventArgs e)
   6:     {
   7:         setCookieForTimezoneOffset();
   8:     }
  10:     private void setCookieForTimezoneOffset()
  11:     {
  12:         if (Request.Cookies[mTimeZoneCookieName] == null)
  13:         {
  14:             ClientScript.RegisterStartupScript(GetType(), "Timezone",
  15:             string.Format(
  16:             @"<script language=""javascript"">document.cookie = ""{0}="" + new Date().getTimezoneOffset(); </script>",
  17:             mTimeZoneCookieName));
  18:         }
  19:     }
  21:     public int TimezoneOffset
  22:     {
  23:         get
  24:         {
  25:             return getTimezoneOffset();
  26:         }
  27:     }
  29:     private int getTimezoneOffset()
  30:     {
  31:         int returnValue;
  32:         returnValue = (Request.Cookies[mTimeZoneCookieName] == null) ? 0 : Convert.ToInt32(Request.Cookies[mTimeZoneCookieName].Value);
  33:         // JavaScript returns 300 if the offset is -5 offset so I convert the number
  34:         return (returnValue / 60) * -1; 
  35:     }
  36: }

The only catch is: The very first time a user loads any page the times will be GMT/UTC after a single postback everything is as right as rain. On way this could be corrected is by tweaking the “Timezone” start up script a bit to force a refresh. (And that’s just one solution, I’m sure you can come up with another.)

I hope that helps someone.


Monday, February 28, 2011

My TortoiseSVN Global ignore pattern

Some files shouldn’t be committed into version control. Usually things generated by the computer (i.e. exe’s, dlls, etc.) and user specific files (i.e. *.suo, *.user, etc.)

Here is the global ignore pattern I use for TortoiseSVN to exclude such files.

*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp .DS_Store _ReSharper.* *.resharper *.suo *.user bin obj
</ pattern>

Hope it helps someone.