ASP.NET – Custom validator for list controls

All I have to share right now is a topic we’ve been struggling a little with at work. CheckBoxList and validators. Most validators work only with a subset of the web controls in ASP.NET. For example, you can’t add a RequiredFieldValidator to a CheckBoxList. Why? Dunno why exactly, pry something to do with the multi-select controls vs. others like RadioButtonList that are single-select. Still not a good reason at all…

But I was finally able to find an article explaining how to create a RequiredFieldValidator that works with CheckBoxLists. Unfortunately it doesn’t work on the client-side; the scripts are disabled, as they don’t work with these ‘excluded’ controls. But I’m working on that right now and will post the solution when I have it….

UPDATE: Here’s the answer to the client-side validation problem. It creates a JS function that the validator calls for its evaluationFunction. Pretty sweet!

OO/.NET – Disposing of unmanaged resources

There are two areas of GC to be aware of. First, GC does not happen right away. If you aren’t proactive about removing objects, they stay in memory waiting for GC to pick them up (destroy them). And GC has its own algorithm for figuring out how to do so, so you never know exactly when that will be, or if soon enough to save your app from high load. This is where calling Dispose() on a object comes in.

For today’s subject, I also want to mention releasing unmanaged resources efficiently, in case your caller code forgets to Dispose of them, or can’t wait for GC. These resources (such as window handles, etc.) are not automatically disposed of. In a sense, they get orphaned as their owner (your managed class) has disappeared. The garbage collector doesn’t know how or want to find all such resources and/or how to destroy them as well, nor should it have to; GC is managed, it wouldn’t know unmanaged resources exist. If it had to worry about not only the base object you asked it to collect, but also objects beyond that one, GC would become even more taxed and complex than it already is.

Here’s a very good article on MSDN showing how to properly code classes that use such resources and how to efficiently release or recycle system resources inside the application.

ASP.NET Cache ‘Locking’

Looks like you can count on blogs every 2-3 days, sometimes more when I have the time….my bar time gets in the way…..

Thought I’d pass along another ASP.NET performance-related article. This one discusses how to handle concurrency issues with the Cache object. Not many developers realize this problem, where multiple threads (pages) could be trying to access a Cache object at the same time, causing it to possibly be loaded multiple times. This articles gives a good explanation of the problems, and how to avoid it through techniques such as thread synchronization.

Server Explorer -AND- URL Paths

Don’t have access to SQL Server Enterprise Manager/Query Analyzer at home? One of the little known jewels in VS.NET is the Server Explorer. Until a couple of months ago, when a co-worker had just that problem and discovered how much was really in there, I had only looked at it a little, not realizing how useful it was for data-intensive applications.

To bring up the explorer, goto ‘View’ -> ‘Server Explorer’ (shortcut Ctrl + Alt + S). You’ll see two sections, ‘Data Connections’ and ‘Servers’. The Data Connections section allows you to create OLEDB connections to databases on your network (or locally). The Servers section gives you the opportunity to remotely view Event Logs, Performance Counters, etc. on remote machines.

While the Servers section is useful for remote development or monitoring, I spend most of my time in the Data Connections section. The interface gives you most of the capabilities you need in Enterprise Manager: design tables, retrieve/alter data, run SQL queries and stored procedures, and even the ability to step into and debug a stored procedure running! This all comes in a UI that looks strikingly similar to Enterprise Manager’s windows. In addition, any connections you add will show up in most data wizards in the Designer.

NOTE: Most of the options are accessible via a right-mouse click.

One other quick note. I get so confused when dealing with URLs, as to what methods on HttpRequest, etc. are going to give me what ‘path’…is it virtual, or a physical path, and what does it include. I ran across this article today while looking for a related answer, pretty nice summary of the different methods!

ASP.NET, Threads and Asynchronous Calls

Doing a little refresher on ASP.NET and optimizing performance thru threading/asynchronous calls. It’s a very important topic that not many developers consider (or consider properly) when building applications.

This first article from MSDN serves as an excellent low-level discussion of how threading is done, as well as discussing the alternatives and their pros/cons.

Right now I’m reading through another article I just found on MSDN in a similar vein, talking about using asynchronous calls with web services. I’ve seen similar articles before, hopefully this one will be sufficient, otherwise I’ll have to go hunt down those other sites.