Jul
26
2010

How to Get jQuery 1.4.2 IntelliSense to Work in Visual Studio 2008

jQueryIsReady For those still using Visual Studio 2008 and developing using jQuery, you will no doubt desire the use of IntelliSense in your text editor to browse the jQuery objects.

To make sure you get this benefit, you must have SP1 for Visual Studio 2008 applied and run a patch which you can download here.

Download jQuery 1.4.2 and the –vsdoc.js for jQuery 1.4.1 and place them in the same folder in your web app.  Rename the –vsdoc.js file to “jquery-1.4.2.min-vsdoc.js”. 

Add a script tag to the top of your ASP.NET web form or master page:

 

You should now be able to see IntelliSense at work anywhere you reference jQuery.

    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Jul
23
2010

Getting the Event-Causing Control ID in ASP.NET Web Forms

Very early in the life of a web form in ASP.NET, you may need to know what control fired the event that caused the post-back to occur.  Perhaps you need to know what button was clicked before the click event handler is executed.  If that scenario is the one you find yourself in, then the following code can help!

If you include the following extension method in your code, you can get the ID of the event causing control from the HttpRequest instance:

public static string GetEventTargetId(this HttpRequest req)
{
    return GetOriginalControlId(req.Form["__EVENTTARGET"]);
}// extension method

The above code is dependent on a helper method to strip the ugly nonsense potentially added while the control was rendered (can now be avoided in ASP.NET 4.0).  The helper method is defined below:

public static string GetOriginalControlId(string renderedControlId)
{
    if (renderedControlId == null) return null;
    int indexOfSeparator = renderedControlId.LastIndexOf('$');
    if (indexOfSeparator >= 0)
    {
        renderedControlId = renderedControlId.Substring(indexOfSeparator + 1);
    }
    return renderedControlId;
}// method
    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Jul
9
2010

Is Your jQuery Ready?

For those that don’t know this, you can shorthand the following script:

$(document).ready(function () {
    alert("Giddyup!");
});

… and replace the above with the following equivalent:

$(function () {
    alert("Giddyup!");
});
    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Jul
8
2010

How to Get the Last Number of an Integer

When I teach my introduction to C# course, I typically provide a tough numeric challenge to stimulate thinking and use all the features of the language learned up to that point.  In a recent class, I was presented the challenge of determining the last number of any integer.  For example:

  • 12 == 2
  • 337 == 7
  • 1000 == 0
  • 987654 == 4

In each example above, I needed to simply return whatever was in the “singles” place – the last number of the number.

My first approach felt like I was cheating, but it worked:

public static int GetLastNumber(string stringifiedNumber)
{
    return Convert.ToInt32(stringifiedNumber[stringifiedNumber.Length -1].ToString());
}// method

After brooding over it, I decided to challenge myself to do this mathematically instead.  Here is the final code:

public static int GetLastNumber(dynamic anyNumber)
{
    double fractional = anyNumber * .1;
    double truncated = Math.Truncate(fractional);
    return (int)(Math.Round((fractional - truncated),1) * 10);
}// method

The use of the dynamic keyword above allows me to pass in any numeric data type.

Updated: Thanks to Nicki for identifying how I over-engineered this problem.  I simply needed to get the modulus of 10 to get what I wanted.  So in one simple statement I could write:

 anyNumber % 10;
    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).
Jul
6
2010

Why I Returned to OmniFocus

OmniFocus Inbox As a disciple of GTD (Getting Things Done™), I need to have a “system” for organizing my action items, projects, areas of focus, goals, reference materials, among other things.  In the years that I have implemented GTD methodologies, I have changed my “systems” frequently (which is a problem, and worthy of another blog post).  I have tried Outlook hacks, paper-based implementations, Toodledo, Things, Google Tasks, and other short-lived solutions.

Another application that many of my co-workers use is called OmniFocus by the OmniGroup.  I also used this application a while ago.  This is probably the best GTD application on the market.  Unfortunately, it is only available on Mac OS, and there is no web presence or service to access the data.  These factors have held me back from using the application despite its superiority in features.

Since I own both the iPhone and iPad, I have experimented with OmniFocus once again.  Recently, OmniFocus was updated to take advantage of iOS 4.0, and I have been happy with things so far.  I also own a MacBook Pro, but spend most of my time in BootCamp running Windows 7 (which rocks on a Mac by the way).  So while I am in Windows, I keep track of my projects and action items on my iPad (or iPhone if I am out and about).

I am still disappointed with the OmniGroup for not making my data available through a web UI (so I can manage from PC).  I am also frustrated that there has been no release specifically targeting the iPad.  I would even be happy if OmniGroup provided the data through a web service or OData.

So I have returned to OmniFocus because it is the best GTD so far.  Having said that, I believe in this saturated market there is still an opportunity for a better application to emerge.

Stay tuned…

    Copyright © Microsoft Corporation. All rights reserved.
    The code provided in this post is licensed under the Microsoft Public License (Ms-PL).

Resources

Archives

Team Blogs

Download OPML file OPML