February 08, 2007

HowTo: Strongly Typed View with SubSonic

I had a little trouble yesterday trying to get a Strongly Typed view working correctly in SubSonic. I spent a good 2 hours beating my brain trying to figure it out (I don't have internet at home yet - no Googling). Well after an hour break I came back and it hit me. It's very easy to implement, so lets start.

First off SubSonic will create your view as a collection. If your view is named v_RecentShares then you'll get a VRecentSharesCollection object.

You can then use that to query your view and iterate with a Strongly Typed reference:

Dim V as VRecentSharesCollection() = new VRecentSharesCollection().Load()
Dim Row as VRecentShares()
 
For Each Row in V
Dim ShareName as String = Row.ShareName
Next

kick it on DotNetKicks.com

February 05, 2007

Book Review: 175 Ways to Get More Done in Less Time!

I just read through this book and it has some great tips. Straight and to the point, no models, history, deep discussions, etc... Just straight to the point, trivial tips that you can start using literally right now. If you're looking to get a few extra ideas on how to squeeze more time out of your day then this is a handy start.

I've got a few tips bookmarked. This isn't a one-time read, as a matter of fact I'll be going back and bookmarking a few more tips suggested in this book. This book even sprung another idea on me for my website.

The book is only 36 pages long and you can read through it, front to back, in no more than 15 minutes. You'll want a highlighter around to underline the tips that can help you. Most will help, some you already do, but you'll certainly pick up some new ideas.

175 Ways to Get More Done in Less Time!
by David Cottrell and Mark C. Layton
CornerStone Leadership Institute © 2004 (36 pages)
ISBN:0965878848

kick it on DotNetKicks.com

January 31, 2007

Reading value of a CheckBox in DataGrid

Want to know how to get the value of a check box in a Template Field inside a DataGrid? Check it out:

        Dim chkMiss As CheckBox

' Go through each row and find a check box
For Each i As DataGridItem In dgActive.Items
chkMiss = CType(i.FindControl("chkMiss"), CheckBox)

' Check if miss was selected
If chkMiss.Checked Then
' Use my checkbox
End If
Next

That's all you need on the server-side code, and now for the HTML... Inside your datagrid just create a template column and it should look something like:

  <asp:TemplateColumn HeaderText="Select Check Box">
<ItemTemplate>
<asp:CheckBox id="chkMiss" Text='SomeText' runat="server">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>

And you're done! The same method applies to all other controls as well.

kick it on DotNetKicks.com

kick it on DotNetKicks.com

January 20, 2007

Sys is undefined - AJAX 1.0 RC

Okay, I am frustrated. My project was working fine a few days ago and now I'm getting the dreaded Sys is undefined error. I've been trying to track it down with no luck.

A Google search shows that there are many people with this same issue. I've gone through my config file and everything looks correct.

I'll keep working on it and will post here as soon as anything comes up.


Update: A little farther...

Ok it seems as if my ScriptResource.axd file is being encoded! I'm using the Blowery HTTP Compression Module and after adding an exclusion for the mime type: application/x-javascript my WebResource.axd started coming back - it was coming up with a blank file before. However I keep getting the error Invalid character. I think its because ScriptResource.axd is encoded and not being decoded!

It's also telling me that the Type.RegisterNamespace function cannot be found (this function exists in ScriptResource.axd). I checked with Fiddler and ScriptResource.axd is being GZIP encoded. So I removed any reference to blowery and still no luck! You can view my posts on the ASP.NET Forum here for further detail, my user name is SuperGhost (the Batman logo).

You can check if your script is being encoded by opening up Fiddler and calling your ScriptResource.axd. Run your page first and get the source. The source will contain the correct path and querystring to the ScriptResource.axd file as well as the WebResource.axd file.

I'll post an update when this gets resolved!


Resolved: Finally

Ok found the problem a few days ago. The file was being encoded and the problem was that I had earlier uncommented a line in my web.config and then commented it back out again. Apparently the setting remained, not sure why. This is the line:

<scriptresourcehandler enablecompression="true" enablecaching="true">

You can see the enableCompression is set to true. So a simple change was all it needed. I uncommented the line and set compression to false:

<scriptresourcehandler enablecompression="false" enablecaching="true">

And that's it! Resolved! Also the Blowery HTTP Module was not affecting the script at all. I hope this helps anyone else having this issue!

kick it on DotNetKicks.com

January 16, 2007

Blocking DoS attacks, maybe...

Mads / .NET Slave has posted an HttpModule for blocking DoS attacks. How does it work? Well any IP address that accesses your page more than 10 times per second gets banned for 5 minutes. All settings are configurable, for example you could ban on 15 requests per 2 seconds for 10 minutes.

I would certainly recommend that you do some testing to find a decent setting. Also some comments have come up on Mads' post wondering about more detail like: What if you're being hit by AOL's proxy server or a search engine bot? You'll have to take into account how your visitors access your website too. I will be playing around with the source and seeing how it reacts to an AJAX-enabled site as well.

kick it on DotNetKicks.com

January 12, 2007

A Better IIF for VB.NET

After browsing around a while I came across a code snippet that is very useful yet hardly used! I've always been jealous of C#'s easy-to-use ? operator:

if x ? a : b
But I didn't mind using IIF for VB.NET. Anyways, apparently IIF does some nasty typecasting in the background and isn't very Option Strict On friendly. Say hello to the new and improved Generic IIF function:
Public Function IIf(Of T)(ByVal expression As Boolean, _
        ByVal truePart As T, ByVal falsePart As T) As T

  If expression Then
    Return truePart
  Else
    Return falsePart
  End If
End Function

kick it on DotNetKicks.com

January 11, 2007

Followup: SubSonic in WinForms or DLL

Looks like the feature to use SubSonic in WinForms and DLL's will be added to the next SubSonic release!

Also there's a new version of the tool that works with the SubSonic 1.0.6 release. It also now works with Enterprise Library projects as well. Thanks DevInstinct / Martin!

kick it on DotNetKicks.com

January 03, 2007

SubSonic in WinForms or DLL

I was recently trying to get SubSonic integrated into my Business Layer DLL, which compiled with my web project, and found a great tool in the SubSonic forums. It was a bit of a nuisance to manually do this after each release but thanks to DevInstinct in the forum who has created a Custom Tool add-in for VS 2005 to allow you to use SubSonic in a DLL or EXE (You can use it in Web Application Projects and WinForms too).

This is great because now I can properly separate my Presentation Layer with my Business Layer and package SubSonic in only the Business Layer project! Scale away! This tool is great so go check it out and show support for it so we can get it added to a future SubSonic release.


P.S. I don't pay too much attention to punctuation or properly formatted paragraphs, enjoy ;-) oh and Happy New Year!

kick it on DotNetKicks.com

December 28, 2006

SubSonic 1.0.6 Released

Merry Christmas... SubSonic 1.0.6 was released on Tuesday.

No change log yet but we'll just have to wait and see.

kick it on DotNetKicks.com

December 21, 2006

Taking your ASP.NET app offline

Something really interesting and useful for ASP.NET is the ability to take your application completely offline. As a matter of fact when you publish your website Visual Studio 2005 takes your application offline. So even if you go to mysite.com/here/there.aspx you will still get an "application offline" message. The best part is that you can customize the message.

All you have to do is upload a "app_offline.htm" file to your website. Thats it! You can create your own custom message in the htm file. There's no special tags to use, the file itself lets .NET know you want your app offline. Just remember to take it off ;)

If you want more details, including an example file, check out the 15 Seconds article: Taking an ASP.NET 2.0 Application Offline.

kick it on DotNetKicks.com