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