ASP.NET MultiLine TextBox MaxLength Validation

There have been many articles and forums addressing the fact that the MaxLength property of the ASP.NET TextBox does not work when you set TextMode to MultiLine. The majority of these solutions use the KeyPress and OnBlur events. This brings with it lots of JavaScript and a host of browser issues. I was impressed by the RegularExpressionValidator options because they can tie in to the AJAX ValidatorCalloutExtender. I also like the server-side validation that you get with the native validation controls.

The solution I settled on is a combination of all the above. I use an ASP.NET RegularExpressionValidator on the MultiLine TextBox. The code looks like this:

<asp:TextBox runat="server" ID="txtDescription" TextMode="MultiLine" Rows="5" Width="300" />
asp:RegularExpressionValidator runat="server" ID="revtxtDescription" ControlToValidate="txtDescription" ErrorMessage="Exceeds 500 character maximum." ValidationExpression="^[\s\S]{0,500}$" Display="None" />
ajax:ValidatorCalloutExtender ID="vcerevtxtDescription" runat="server" TargetControlID="revtxtDescription" />

Good so far, but to quote Mark Hildreth:

“I agree that that works for preventing users from posting too much text, however it does’t prevent them from typing more than 500 characters into the box. The validators only perform their validation in the onchange event which is not triggered on every key stroke. Imagine your dismay if you spent 10 minutes typing into a textbox, only to have the form say you have exceeded the 500 character limit?”

The JavaScript below will call this RegularExpressionValidator every second. I find that it does not noticeably slow down the form.

<script type="text/javascript">

    $(document).ready(function () {
        setInterval("validateDescription();", 1000);

    function validateDescription() {
        var myValidator = document.getElementById("<%= revtxtDescription.ClientID %>");


Now as the user is typing, they will be warned within one second of exceeding 500 characters. If they paste into the textbox, it will alert them too.

Remote Desktop Services Multiple Sessions

As far as I can tell, it is trivial to enable multiple simultaneous remote desktop sessions for Windows Server 2008.

  • Open gpedit.msc
  • Navigate to Computer Configuration -> Administrative Templates -> Windows Components -> Remote Desktop Services -> Remote Desktop Session Host -> Connections
  • Double-click “Restrict Remote Desktop Services users to a single Remote Desktop Services session
  • Check “Disabled” and apply.

There is one caveat, however. It seems to leave a Console session active at all times. You can log off the Console session via Task Manager. If you connect to it (by right-clicking it in task manager) it doesn’t seem to be doing anything.

Scripting.FileSystemObject Read Subfolders

Read subfolders with the Scripting.FileSystemObject:

Dim fso
Dim ObjFolder
Dim ObjSubFolders
Dim ObjSubFolder
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set ObjFolder = fso.GetFolder([folder path])
Set ObjSubFolders = ObjFolder.SubFolders
For Each ObjSubFolder In ObjSubFolders
Response.Write(“<li>” & ObjSubFolder.Name & ” – ” & ObjSubFolder.Path & “</li>”)

Entity Framework Count Child Entities

Expanding on the post “Entity Framework Filter Child Entity“, I finally figured out how to get a GridView to show the count of child records. Unfortunately I am returning the whole set of entities and doing a Count on them. It’s not a problem in this case. I’m just happy it works.

Dim query = (From x In db.OrderChecklistItems Where x.Enabled = True Order By x.Enabled Descending, x.ItemText Select OCI = x, _
OD = From y In x.OrderDocuments Where y.OrderID = OrderID, _
CS = From z In x.OrderChecklistSelections)
Dim customers = From item In query.ToList Select item.OCI
GridView1.DataSource = customers

Then in the GridView:


Entity Framework Filter Child Entity

I was looking for a way to filter child entities with eager loading. I ran into this useful blog post by Beth Massi on the subject.

Here is the code I ended up using. It doesn’t work with server-side paging, but I didn’t need it in this case.

Dim query = (From x In db.OrderChecklistItems Where x.Enabled = True Select OCI = x, _
OD = From y In x.OrderDocuments Where y.OrderID = OrderID)

Dim customers = From item In query.ToList Select item.OCI

GridView1.DataSource = customers