Sunday, January 30, 2011

Spell Checker Extension For VS.NET 2010

OK there is a really useful extension available for free to VS.NET 2010 named "Spell Checker". It shows misspelled words within commented sections with the traditional red squiggly line under the word as seen in Office products. Obviously correctly spelled words are not critical to an applications performance, but well formed internal documentation that reads well such as commenting is important.

You can download it for free by going to Tools -> Extension Manager and then select 'Online Gallery' from the left-hand side. In the search box type in the top-right hand corner, type in "spell checker" and search. The 1st extension created by Roman Golovin and Michael Lehenl (thank you) named "Spell Checker" is the one to download and install (shown below).



As you can see below, just hover the mouse over the misspelled word for the little box to display, which upon clicking will bring up the properly spelled words. There is also the ability to "Add to dictionary" which is nice, because often many words we use are technical and not in the dictionary.


It can also be downloaded directly from the link below:
Spell Checker Extension for VS.NET

Wednesday, January 26, 2011

Use LINQ To Get The SUM Or Total Of A Property Value On An Object Collection

If you have an object collection say List(Of <T>) and you want to add up all of the values of a single property of the proper type (Integer, Double, etc.), you can do this using LINQ and a lambda expression. We will use the SUM LINQ Extension Method directly on the collection that implements IEnumerable(T), and provide it an anonymous function that takes the property value to be added together. So here is the code using an object collection which I had already populated previously:

'Use the LINQ SUM Extension Method to iterate over the collection and extract the total.
Dim Total = MyDataCollection.Sum(Function(x) x.PropertyOnXToSumTogether)
The anonymous function takes a parameter which will represent the individual instance of the collection, and then uses the property designated to be iterated over and added to the total.

Using Fiddler With VS.NET And The Local Web Development Environment 'Cassini'

If you use Fiddler to monitor traffic to your web sites, you have probably found it useful for debugging issues like 404's or 403's etc. However if you want to have Fiddler show traffic from sites you are debugging through your local VS.NET web development server, then you need to add a '.' period after the word 'localhost' in the URL. Also make sure to add it prior to the designated port as displayed below.

After refreshing the page, you can see the output in Fiddler.


Monday, January 24, 2011

How To: Scroll To The Bottom of an ASP.NET Web Page After Postback

Not a post about bleeding edge technology here, but just a little technique I ran across here for ASP.NET web pages. I needed a way to have the focus shift to the bottom of a page after a button near the top of the screen was pressed. Unfortunately setting focus via Page.SetFocus(Me.BottomOfPageServerControl.ClientID) did kind of work, but only shifted to the top of the control, and the control had a large height. Therefore the scroll bar was still not at the bottom, and the resulting pertinent data in my situation was at the bottom of the page.

The solution? Place a server control at the bottom of the page with CSS properties that prevent it from physically being viewed, don't affect scroll bars, and yet can still have focus shifted to it.

So begin by placing an ASP.NET button (or any other small server control) at the bottom of your markup, and add some inline styling to be most compact and streamlined if you wish:

<!--Button will render, but not actually be visible to the client-->
<asp:Button ID="ui_btnPageBottom" runat="server" Text="Button" style="margin-left:-999px;" />
Notice above the styling places it off the page, but the button will not create any lengthy scroll bars, etc. Lastly, add the code server side on the 'Finally' of the button click event to shift focus to the bottom of the page:

Try
'Code
Finally
'Regardless of outcome, set focus to the bottom of the page
Page.SetFocus(Me.ui_btnPageBottom.ClientID)
End Try
That's it! I am sure there are at least 20 ways to do this, including a purely client side solution with JavaScript, but this was 2 lines of code to accomplish what I needed.