Thursday, June 12, 2008
Occasionally I need to change a a camel case or Pascal case string into a human readable string.  Since I find myself doing this again and again, I figured I better post it here.


private string HumanizeString(string source)
{
StringBuilder sb = new StringBuilder();

char last = char.MinValue;
foreach (char c in source)
{
if (char.IsLower(last) &&
char.IsUpper(c))
{ sb.Append(' '); }
sb.Append(c);
last = c;
}
return sb.ToString();
}

Thursday, June 12, 2008 3:47:38 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Wednesday, March 26, 2008
Find controls in a page or another control

List<T> FindControls<T>(Control control) where T : Control
{
List<T> list = new List<T>();

foreach (Control c in control.Controls)
{
if (c is T)
{
Global.LogDebug(c.ID);
list.Add(c as T);
}

list.AddRange(FindControls<T>(c));
}

return list;
}


private Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
{
return root;
}

foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
{
return t;
}
}

return null;
}


Wednesday, March 26, 2008 9:35:09 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Wednesday, January 09, 2008

OK, so I've been using Python quite a bit lately and I've been enjoying it.  I've been getting stuff done with it too.  Python inter-operates with COM quite well and that saved me a lot of pain yesterday.  However, learning Python has caused me pain in other areas.

Yesterday I had to perform some maintenance in a C# ASP.NET app that I had written not too long ago.  Even though I use the CoolStorage.NET and some other nice time savers, it has become painful to write C# code.  It's just too verbose.

I used to marvel at people who claimed that you don't need an IDE to develop with Python.  I thought that was blasphemy as Visual Studio was the bee's knees in C# development.  However, I'm amazed at how much more I'm engaged in coding when I'm writing Python (or JavaScript).  You have to pay attention to what you're doing, no IDE is going to help you out.  However, this heightened state of concentration is actually fantastic for writing good code.

I use Notepad++ as my editor for Python (and JavaScript and HTML, etc) when I'm not using C# and Visual Studio.  I find its adequate for the job and it does have a function/method browser built in.  It also does HTML auto-complete and it can highlight a psp template file where I have Python, HTML and JavaScript all in one file.  It's also very stable, something that Visual Studio is not.

Visual Studio 2005 is flaky.  Sometimes all my Windows will rearrange or reset.  Other odd things happen and I find myself re configuring my layout from scratch.  Actually worse than scratch because every thing is helter skelter around. 

The worst part though is the amount of code I have to write to keep the compiler happy.  I know what I want to do and I know how I want to do it but I have to tell the compiler what I'm doing ahead of time so that it's happy.  Honestly, this is a great feature for a newbie or someone who really doesn't want to learn the language.  However, it becomes a burden after a while.  The C family of language has so many tokens (symbols like { [ ( ; , for while do foreach if) that your code becomes very noisy very fast.  Python is nice and clean which is something that I've come to appreciate.

I think I've found a better appreciation for Python (and JavaScript) because I've used C#/C++/Java.  For my everyday programming needs Python can handle everything I need to do.  However, at my current job getting Python into the mix might be a bit hard.  However, it might be worth it.  We spend so much of our day writing Programs that should just be nice and easy scripts.  We have so many programs and projects that could easily be one python file.  We do a lot of file transfer and validation. 

So yes, I'm feeling the pain of C#.  I just don't need/want that bug IDE and big language for what I need to do. 

Python does it faster, smaller and cleaner. 

Wednesday, January 09, 2008 9:33:53 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Wednesday, December 05, 2007
http://www.aspfaqs.com/webtech/042606-1.shtml

One of the best (not to mention easiest) paging methods I've seen.  In fact it requires no temp tables or table variables. 

Paging is something that is so common yet seems to hard to get right and keep performant that it pays to have a nice easy template to start from.  I've posted this mainly for my own benefit so I have a permanant bookmark to this code.

The example uses a stored procedure, but its important to understand that a stored procedure is not required to make this work.

Here's the code:

CREATE PROCEDURE [dbo].[usp_PageResults_NAI]

(
@startRowIndex int,
@maximumRows int
)
AS

DECLARE @first_id int, @startRow int
    
-- A check can be added to make sure @startRowIndex isn't > count(1)
-- from employees before doing any actual work unless it is guaranteed
-- the caller won't do that

-- Get the first employeeID for our page of records
SET ROWCOUNT @startRowIndex
SELECT @first_id = employeeID FROM employees ORDER BY employeeid

-- Now, set the row count to MaximumRows and get
-- all records >= @first_id
SET ROWCOUNT @maximumRows

SELECT e.*, d.name as DepartmentName
FROM employees e
INNER JOIN Departments D ON
e.DepartmentID = d.DepartmentID
WHERE employeeid >= @first_id
ORDER BY e.EmployeeID

SET ROWCOUNT 0

GO






 |  | 
Wednesday, December 05, 2007 2:43:40 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, October 19, 2007
Nullables always felt not quite done.

Here is a technique to add an extra minute to the microwave timer and get a more fully compatible conversion function:

http://blog.pumacode.org/2006/05/18/using-convert-changetype-on-nullable-types/

Nullable types are awesome for dealing with databases.  Its a fact of life that most databases are going to use null and you need to deal with it in your code.  However what does null map to for a value type? 

The answer is unknown.  If C# were truly object oriented then wouldn't value types be reference types instead.  I'm guessing there are some big performance implications to this.  So we have nullable types.  A solution that is almost ready for prime time. 

Side Note:  If you truly wanted a consitent web front end for a database then null would map all the way through to things like dropdownlists where they would map to the default "please choose" option.  This would be an awesome rails like feature.  I'll have to do that when I get around to building my own web framework.

That's not likely to happen anytime soon.  I actually built server controls that did the above.  However, the overhead of maintaing server controls and making them behave just like regular built in server controls is just too much of a burden at this point.  I'll have to revisit this at some point.

Friday, October 19, 2007 10:28:47 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
The one thing that irks me about compiled code is the compilation tax.  It takes a while to re compile everything even if there is only a small change in a page or class.

Here are some tips to reduce those build times.

http://weblogs.asp.net/bradleyb/archive/2005/12/06/432441.aspx


I have to say that it certainly seems faster after I've used these tips.

One improvement I have made is to not debug using Visual Studio.  I simply start app and stop it right away.  I then just browse to my web site with another browser instance and test that way.  The development web server will just sit there running and serving up content. 

I find this way that I use logging much more than debugging.  Of course, there are some problems where debugging just can't be beat but those instances are few and far between. 

This method works really once especially if you have seperate assemblies for each page/folder.

I find that I only build the whole site if I make signifigant structural changes to the site like renaming classes. 

In the end, faster edit, test, debug cycles are what we are after.  We want the advantages of a dynamic language without the penalites. 

Friday, October 19, 2007 2:24:38 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, October 12, 2007

ProMesh is too immature at this point to complete the project I am working on. I think given a few weeks or months this framework will be top notch.

Right now however I am constantly getting the latest version to get around some bug only to discover another bug. I don't want to come across as negative about ProMesh.Net, again I think it will be one of the best frameworks out there once its matured a bit.

-- Update --
Again, to make it clear I think ProMesh is a good framework.  I have released a small project with it and it workds great.  My problems are with the validation scheme that changed and a looming deadline.  I am still using it for other projects.  My rants below are about me screwing around too much and finding myself short on time and having to use WebForms.
-- End Update --

Back to the present, I need to get work done. I have spent a little too much time playing with ProMesh and some various other languages and frameworks. I neeed to get some work done. So I'm back to ASP.NET WebForms.

It's telling how poor WebForms are as I can barely get a simple form working correctly. Control postbacks and the whole business is absolutely frustrating. I want to make a form that changes which controls are displayed based on the value in a drop down box. Simple right? Wrong. I'm once again battling the stupid page lifecycle. Is this really the best we have?

I'm looking forward to seeing Microsoft's MVC for ASP.NET. I hope that takes .NET web development in the right direction.

Many people compare WebForms to WinForms. Something about WEbForms being VB6 on the web. Well I can tell you VB6 was never this unecessarily complicated. Good grief.

I think it's a bad sign when you spend 80 percent of your development time working around your framework instead of with it.

Friday, October 12, 2007 1:02:04 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Thursday, October 11, 2007

Everytime I try a new language or technology I eveluate it based on what it can do for me. Will it make more productive or will it teach me something. I'm not a big believer that learning language X will make you a better programmer in language Y. I think there is some truth in that but not as much as some would lead you to believe.

Above all else, I look for pragmatic solutions. What can technology do for me? I think Ruby on Rails is a decent example of pragmatic software. It has its flaws but in the right scenerio I think its a very practical solution.

So when I go down the rabbit hole with some new language/platform, etc, I'm looking for benefits. I know what C# and ASP.NET can do for me. I've used them long enough to know the ups and downs and i'm constantly looking for ways around those low points. ASP.NET webforms is a great example. I hate using them. In anything but the most simple situations, they break. They "leak" in that they are not the best way to abstract the web. They represent the underlying web server event cycle more then anything. And they are painful to use.

I've looked at Boo, Nemerle, F#, IronPython, L#, Cat and probably some that I can't remember JUST in the .NET realm. This doesn't include my research into Lisp, Scheme, Scala, Factor, Ruby, etc. These .NET technologies have other benefits like cross platform abilities that make them attractive. With the .NET languages/tech, I'm looking for ways to solve or alleviate my C#/ASP.NET pain.

Boo seems to be a good language. It lacks good Visual Studio support though. This means I lose productivity to gain a cool language.

IronPython has a sweet spot in scripts and possibly web pages. I like the quick turnaround of editing a script and seeing the results without the long compile time.

On the framework/library front there is ProMesh.NET and MVC framework that replaces WebForms. It's pretty good but it still has some bugs. There is also MonoRail but I haven't gotten the courage and the time to test it out. It looks massive and I don't really get Inversion of Control and Dependency Injection yet. However, they sound odd and a bit scary. Do I really need them just to have a decent web framework? I don't need these in PHP.

A solid win on the ORM front is CoolStorage.NET. This thing blows the doors off of anything else I've used bar none. It is the optimal combination of light weight yet powerful features. I think CoolStorage wins by being a C# first project. It is not a clone of a Java project. CoolStorage takes advangtage of attributes and generics to produce a terribly productive product.

So with one win and so many that qualify as so close yet so far, what is a practical programmer supposed to do? The only thing I can do is spend hours testing out new languages and frameworks to see if there is anything out there. At least at the end of the day, if I don't find anything, I know that C# is king and I'm not left wondering.

So I must continue my crusade for the best even though most days its a big pain. I've recently found F# and it looks very nice. Visual Studio support, a real REPL and syntax and conciseness like a scripting language yet with a typing system more powerful than the one in C#.

So yes, these little discoveries are worth all the pain of downloading, installing, and compiling countless new programs. I can put my mind at ease and keep up on the latest developments. In the end there is something to be said for intellectual stimulation and if there is practical use then all the better.

Thursday, October 11, 2007 8:49:30 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Thursday, July 19, 2007

Joel on Software's admin dude wrote a post about how they are doing db backups. 

http://www.michaelgorsuch.org/wordpress/2007/07/11/some-times-you-have-to-roll-your-own/

Funny thing is that this is how all databases fundamentally perform backups.  Just makes me think that once you get X years under your belt you come to the conclusion that you've seen it / know it all.  Fundamentally, this stuff is simple, the problem comes into play when MS (or vendor of choice) tries to layer multiple extra layers of shite on top of a simple concept.

Html, javascript, css are easy (compared to multi-threaded servers and C++).  ASP.NET makes them much more complicated then the have to be.  I'm currently in the process of removing all of the ASP.NET AJAX CRAZY framework out of the whatsyour20.com as it's just too damned complicated for what you get.  Also I think the ASP.NET page life cycle is ridiculous.  We stopped teaching ASP.NET for web development at the college I used to teach at because it was just too hard for students to figure out.  Ironically, MS made ASP.NET follow the desktop paradigm to get the Windows Forms dudes (like myself) to buy in, which caused ASP.NET to become almost incomprehensible for those that wanted to learn web development without having any desktop experience. 

There is a reason PHP and MySQL are so popular.  Simplicity has a place and that place is HUUUUUGE.  It's a big house on the hill overlooking the lake with a great view. 

The point of this rant is that sometimes we make things so complex by trying to make them simple.  Instead are we perhaps better off if we let the complexity stay were it needs too. 

ASP.NET missed being one of the best pieces of software ever designed.  Why?  Page lifecycle (why must i figure out if i need init, load, pre init, pre load after load, after init, and the if (postback == false) { madness).  The dirty little secret about ASP.NET is that nobody needs a freakin' data grid!  They are completely useless.  Html tables are easy to make.  Grids are ridiculous and bloated and don't support Ajax worth a damn. 

Why I'm at it I should rant about how SQL Server 2005 leaves out features already in 2000.  But this post is getting too long as it is.

ASP.NET needs a sane alternative implementation that works with the web instead of against it.

 |  | 
Thursday, July 19, 2007 9:52:46 PM (Central Standard Time, UTC-06:00)  #    Comments [1]
 Wednesday, May 23, 2007
There is a discussion over at Scott Hanselman's site about URL Rewriting in ASP.NET.  I found a similar article about URL Rewriting in ASP.NET on Coding Horror


Synopsis:

Here is a brief synopsis of the problem.  In order to have an http module or handler take care of your url rewriting you must have all requests sent to aspnet_isapi.dll via application extension mapping in IIS 6.

Here is an example:

I want http://whatyour20.com/modules/view-location.aspx?locid=1234

to instead look like:

http://whatyour20.com/locations/yellowstone-national-park/

I do this for several reasons.  The number one reason is SEO.  We want google to give google a good idea of what this page is about.  Obviously the latter url does the much better.  It also gives the users an idea of what the link is about.  Number two, it makes our links hackable.  Number 3, it makes our links more aesthetically pleasing.  I think that is very important.  If I see a url that is meant for people instead of machines, I know the web site creator took some time to dot every i and cross every t.  Number four is the less likely option that I will switch technologies and I don't want to lose all my links and there associated page rank if I switch to a new technology or if Microsoft changes thier extension in the future when the next great thing comes out (Silverlight Foundation Server Pages Advanced with SteelRuby, LOL). 

At whatsyour20.com we use UrlRewritingNet.UrlRewrite to handle all url rewriting duties.  UrlRewrite is an asp.net http module that can rewrite any incoming url and it can handle redirects (301, 302).  This works great but it doesn't get rid of the aspx extension by itself.  In fact no http module or handler can do that because iis uses the file extension to determine which program should handle the request. 

So we need to have IIS route all requests for the domain (http://whatsyour20.com) to the aspnet_isapi.dll as stated above.  The problem with this is that now ALL request will go through asp.net.  We may not need this for all requests.  In fact this can be a problem as it can hurt performance.  I've seen the a claim of 30% performance decrease someplace but I don't remember where right now.  However, it's safe to assume that routing static content through asp.net is just not the best solution.

Solution:

The solution?  After the background information we are finally at the payoff.  This is how we get the goodness of using asp.net url rewriting via http modules and the associated debugging and high level of control this brings us WITHOUT the downside of routing static content through asp.net. 

We access all the static content via a sub-domain.  We use static.whatsyour20.com to server all the static content on the site (Right now this is mostly images).  This is very easy to accomplish.  You simply create another web site in IIS, with the path to the same location as your main domain but using the sub domain.  On this domain you DO NOT route the requests to asp.net.  So on this sub domain all content is handled by IIS because it is static.  You could even take that a step farther and put it on a separate server or use another web server that is optimized for static content. 

Our solution works in a share hosting environment because usually you can set up sub domains on shared hosting.  Also you can usually get all requests routed to asp.net if you put in a ticket and simply ask for it.

A nice side effect of using sub domains is improved performance on the client side.  By increasing the number of hostnames (within reason) we can increase the speed at which the page loads.

Here are a few reference articles on multiple domains names to speed up downloads:
http://yuiblog.com/blog/2007/04/11/performance-research-part-4/
http://www.ajaxperformance.com/?p=33
http://www.die.net/musings/page_load_time/

Conclusion:

Using the presented solution we get a urlrewriting solution that is easy to use and configure (all configuration in web.config), transfers easily between hosting providers (again its all provided by asp.net and web.config) and it improves performance.  I'm still looking for any possible downsides.  Please let me know if you know of any.


Wednesday, May 23, 2007 7:29:14 PM (Central Standard Time, UTC-06:00)  #    Comments [1]
 Wednesday, December 27, 2006

If you have been struggling like me to make your sites XHMTL compliant you realize that it’s not an easy task.  Most of the changes are straight forward if you have a validation tool.  I code a lot of sites in Visual Studio 2005 and it will complain like crazy if you have invalid XHTML.  Hence I try not to write invalid XHMTL because I hate errors and warnings and will compulsively try to make my pages as valid as humanly possible.

 

One of the areas where I’ve had the most trouble with this is create bookmarks with anchor tags.  Most of the examples I’ve seen use the name tag on an anchor so that you can link to it using something like http://example.com/test/#somebookmark.  I think this is an underused feature of html as it makes navigation much better and faster, plus it is much easier to link into a page at just the right point with something like this.

 

When using XHTML you should not use the name attribute as it has been deprecated.  Instead you should use the handy id attribute.  The id attribute will work exactly the same way and has the benefit of being compliant.  Plus you get additional validation of making sure each element has a distinct id.  This was a problem with some sites I’ve seen that use name.  I see the same name used all over the place.  This makes linking to the element somewhat difficult and error prone.

 

On a related note, did you know that most modern browsers can link directly to any element that has a valid id attribute?  This is very handy as you want have to include anchor tags all over you html just to get convenient linking.

 

Bad:  <a name="bookmarkid">Test</a>

Better: <a id="bookmarkid">Test</a>

Best: <p id="bookmarkid">the element i actually want bookmarked can be linked to directly</p>

Wednesday, December 27, 2006 1:47:20 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, November 24, 2006
Here's a code tidbit to enable the service broker in SQL Server 2005.  This needs to be running for caching to work in ASP.NET.

IF (SELECT is_broker_enabled
  FROM sys.databases
  WHERE database_id = DB_ID()) = 0
    ALTER DATABASE yourdatabasenamehere
    SET ENABLE_BROKER
    WITH ROLLBACK IMMEDIATE

The if statement checks to see if the broker is already running.  If it is not then it attempts to enable it.  The WITH statement will rollback any other pending transactions that may be blocking this transactions.  This is important because if you run this statement without WITH ROLLBACK IMMEDIATE then it may seem that the batch will not complete.  Again, this is because other transactions or services like SQL Server Agent may be blocking.

Friday, November 24, 2006 8:41:50 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Sunday, November 19, 2006

One argument script pimps use frequently is that it doesn’t matter what tools a contractor uses to build a house as long as the finished product is the same.

The problem with this argument is that the premise and the analogy are flawed.  Comparing the language to the tools is not quite accurate.  The language is more aptly compared to the building materials used instead of the tools.  The tools would instead include things like the IDE.  With the analogy corrected we now see that the choice of building material is very important.  Using 2x4's instead 2x6's will have a big impact on insulation properties (thicker wall cavities) and cost. 

Is this important?  Absolutely!  

Unfortunately, too many scripting language fans (script pimps) make the same flawed analogy in order to justify the use of their pet language instead of a higher performance language like C++ (or C#, Java, etc).  Scripting languages like Ruby are slower then compiled languages.  Also their nature precludes them from having good IDE support.  This is because much of the meaning (context) can’t be derived until runtime so things like IntelliSense become difficult if not impossible to implement. 

Following the scripter’s analysis we are supposed to assume that scripting languages allow faster construction which I would say is another falsehood.  Yes, some contractors might be able to cut wood just as fast with a handsaw but most want to use as much automation as possible.  Hence, table saws, compound miter saws with laser guides, etc.  These automation tools are closer to Visual Studio than VIM. 

In my experience with Ruby (among other languages) I found that the resulting programs were usually slower, which a scripting language will be by its nature.  I also found that the emperor wears no clothes!  Shockingly, developing in a scripting language is slower because of the lack of automation tools.  Example, try to find all references to variable in a Ruby on Rails project.  Now try the same thing in a C# project using Visual Studio.  In Visual Studio it’s a right click and “Find All References”.  In VIM you could search for the references but you don’t have any support for context.  You don’t know that is the only reference to that variable.  You are using a handsaw instead of the best tools available.

I'm sorry but reality demands that 1 = 1 and slower is slower and speed is important.

Sunday, November 19, 2006 9:53:49 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Wednesday, November 15, 2006
Ok URL Rewriting is good.  I won't go into the reasons why but if your searching for it then you already know you want it. 

If you followed the standard progression you probably started with this MSDN article on URL Rewriting.  This implementation works fairly well in ASP.NET 1.x.  However, I've run into problems using this implementation in ASP.NET 2.0 with output caching.  For some reason it breaks output caching.

So what is the solution?

Well I'm glad you asked.  I've found a solution that works quite well with ASP.NET 2.0 and output caching.  The UrlRewritingNet.UrlRewrite assembly provides all the features of the original URL Rewriter mentioned above but also fixes the problems with output caching plus adds some interesting features like redirecting and programmatic access to the rewrite rules at runtime (say that ten times fast!). 

I'm currently using this on http://www.whatsyour20.com and I must say it works quite well.  I also like the fact that it is an active project and it even has a bug tracker system.  There is also a forum for this project.  That's always a good sign.

Enjoy!

 |  | 
Wednesday, November 15, 2006 10:20:11 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
What do you do when you want HTTP Compression to speed up your site but you are using ASP.NET (1.x or 2.0) in a hosted environment?

You get HttpCompress from www.blowery.org/code/httpcompressionmodule.html. This is a module that sits inline and handles compression of your .aspx pages and any other mime type that may be handled by ASP.NET.  This is a pretty good work around if you don't have permission to IIS to enable HTTP Compression there.  Of course that would be a better solution but many hosters won't enable it because of the possible CPU consumption issues.  Oh well, get around them by implementing your own solution!

I know dasBlog uses it in the 1.9.x version.  WhatsYour20.com is also using it at this time.

It's been around for awhile, it's configurable and it's easy to use. 

Give it a try and speed up your site today!

One caveat is testing it using ASP.NET Development Server.  Check out the link for more info.

 |  | 
Wednesday, November 15, 2006 10:10:06 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Tuesday, November 14, 2006
So if you're having odd issues with a JavaScript function like WebForm_InitCallback(); which is a built in ASP.NET JavaScript function and you are using the HTTP Compression Handler from blowery and you are testing a site on the ASP.NET development server, I may have a fix for you. 

In your web.config you should add an exclude statement to exclude the WebResource.axd path:

        <httpCompress preferredAlgorithm="gzip" compressionLevel="high">
            <excludedMimeTypes>
                <add type="image/jpeg" />
                <add type="image/gif" />
                <add type="image/png" />
            </excludedMimeTypes>
            <excludedPaths>
                <add path="WebResource.axd"/>
            </excludedPaths>
        </httpCompress>


Tuesday, November 14, 2006 4:08:45 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, November 10, 2006
A change from asp.net 1.x to 2.0 that has been over looked at least by me is the new data binding expression syntax.  You no longer need something like DataBinder.Eval(Container.DataItem,"MyDataItem")).  Instead you can use something like this: Eval("MyDataItem")).

I know it's not as sexy as caching or super happy fun time crazy drag and drop AJAX controls but the little things make all the difference.

Save your fingers use the new data binding syntax.

Friday, November 10, 2006 4:18:31 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Thursday, October 19, 2006
Here's a quick tip to get png's with alpha transparency to show up correctly in Internet Explorer.  Instead of hacking you website, hack the picture! 

Using a utility like TweakPNG, you edit the meta information of the PNG format to display a white background (or whatever color you want).

Open the .png in TweakPNG and insert a chunk named bKGD using the Insert menu.  Then simply double click your newly created chunk in the main window to bring up a color chooser.  Select the background color and away you go.

 |  | 
Thursday, October 19, 2006 1:24:51 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Tuesday, October 10, 2006

I've posted on the ASP.NET Site about my experiences with WebHost4Life.  At this stage I can't recommend them as a good web host.  It's unfortunate because I've had good luck with them in the past.

I'll keep you posted on what's comes out of the latest hosting catastrophe.

Tuesday, October 10, 2006 8:45:13 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Monday, October 09, 2006

I've found yet another blog and post(sheesh) regarding Query Notifications.  It's a survey asking some general questions.  If you have some complaints or comments head over there and let MS know what you want to see.  I'm still formulating my customer solution.

Observation:  Microsoft has a habit of assuming their solution should be satisfactory and doesn't really give an example of what to do if it isn't.  The user is left to try to piece together a solution that actually works in the real world.  So many of MS's examples assume that you are a drag-and-dropping cheeseball that uses SELECT * for queries and the SQLDataAdapterConnectorInterpreterManagerGateway for all things data. 

What about us folks who actually want to write code.  If I see one more MSDN artcile trumpeting the fact that you don't need to write one line of code, I'm going to puke.  Yeah instead of using a first class IDE supported language to write code I want to put some mish mash of bastardized markup into my ASP.NET page.  That's a great solution.  Try debugging that pile of angle brackets when something doesn't work.  Code is good.  I like writing code.  The IDE supports writing code. 

MS for god's sake let me write code!

 |  |  | 
Monday, October 09, 2006 9:15:52 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, October 06, 2006

In a follow up to my original article on Query Notification in SQL Server 2005, I've posted a question on the MSDN forums about Customer Query Notifications.

I'll keep you posted on whatever solution I come up with.

 

 |  |  | 
Friday, October 06, 2006 10:42:43 PM (Central Standard Time, UTC-06:00)  #    Comments [0]

Seriously, SqlCacheDependancy looked like one of the best new features of ASP.NET 2.0.  Unfortunately, this feature is crippled because of the limited queries you can use.  See this MSDN article for more on that.  Basically you can't use TOP, ORDER BY, COUNT(*) and many other standard SQL clauses.  This is a serious limitation.

I am across this post about one person's attempt to get this to work which led to this post on the rules and some criticisms of the Query Notification mechanismHere is the official MSDN article on creating query notifications

So I wonder if this mechanism is too complicated for real-world use.  It certainly seems nice on first review but after trying to use it I can testify that it difficult to get this working correctly.  The query restrictions really limit your options. 

I'm not ready to give up because the potential up side to this is just too great.  One alternative I'm considering is trying the overloaded SqlCacheDependancy constructor and trying to pass the database and the table.  For joins and sub-queries I may need to hook multiple SqlCacheDependancy objects together with the AggregateCacheDependency.  This seems like a big pain but I think it may be worth it because your site gets much faster once it is all cached up.

 |  |  | 
Friday, October 06, 2006 10:38:50 PM (Central Standard Time, UTC-06:00)  #    Comments [1]
 Sunday, September 17, 2006

Dear C#,

It's taken many months to get the courage up to write this letter.  I have been unfaithful.  I have cheated on you several times.  I won't go into all the details now because I know you will be too fragile to read all of the sordid details but I must confess my first indiscretion.  Her name was Ruby on Rails.  She promised me so many things like an automagical data access layer and super fast site creation.  Only now I realize that she was a cheap whore, pimped by a slick smooth-talking metrosexual Dane with a knack for finding the weaknesses of enterprise developers and exploiting them.

I feel so dirty but I have to say this.  The cheating was only part of it.  I was also using pretty heavily.  I was using VIM several times a day.  That's when I suspected I had a problem.  I think I knew I hit rock bottom when I stooped to hitting the Exuberant Ctags for a fix.  It was Ruby that got me hooked on that crap.  I was so sold on her elegance and simplicity I ignored the hoops I was jumping through to get a decent editor.  The whole time this was happing Visual Studio 2003 just waited patiently for my return with a knowing look.  VS2003 knew she was better but she let me find out for myself.  Like a parent who knows the only way to teach a child a lesson is to let them learn it on his own, you knowingly looked on as I struggled in vain with a succession of seedier solutions for text editing.  There was the aforementioned VIM, SciTE, jEdit, and the abomination to end abominations radrails.  When you are reduced to an orgy of J2EE acronyms to stay agile you know you have a problem.  The Pimp himself has so shamelessly denigrated Java, yet many of his clientèle must turn to Java to make sleeping with Ruby a tolerable experience. 

I now know what it must be like to be a fan of Anna Nicole Smith and then to meet her in person and then to realize what a waste of chemical compounds she has turned into.  She's apparently beautiful but once you here her talk you realize there's nothing going on in there.  So I liken the experience I had meeting Ruby on Rails.  Seemingly beautiful on the outside but utterly deranged once you get passed the magical ActiveRecord song and dance show. 

I'm physically drained.  That's all I can stand to write for now.  I have more to confess like using Daedalus to keep Ruby up on running once she would go on her nightly benders and the inevitable crash afterwords (I guess she was really Like Ms. Smith!) but I will leave that for later. 

Sunday, September 17, 2006 4:02:16 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Wednesday, August 23, 2006

I was testing a new caching implementation for the 20 when I noticed that items I placed in the cache were not staying in the cache.

I ran into this yesterday and luckily I realized what was happening before I did something drastic.  The ASP.NET caching facility automagically dumps items out of the cache when roughly 90% of your physical memory is in use.  So a laptop with 1 Gig of memory has a pretty good chance of seeing this happen.  Load up Visual Studio 2005, Firefox, IE6, the ASP.NET development server and have SQL server running and you are going to get pretty close especially after you've been running all day without restarting any programs or the computer.  The two biggest offenders are typically Visual Studio and Firefox in that order.  In the defense of Firefox I usually have about 15 to 20 tabs open and I have about 15 extensions installed.  Visual Studio can chew up about 400K on its own with all of its child processes running around checking code, looking up help topics etc.

The moral of the story is to shut everything down and then bring it back up so that you have some room cleared out in memory for the obects you want to cache in memory.  Seems like a no  brainer when you think about it.  This is also a good reason to have at least 2GB of memory in your development machine.  That's right TWO Gigabytes of memory.  Someone at work thought I was crazy when I bought my new home machine with 2GB already installed but after using Visual Studio for a while I knew it would come in handy.

 

 |  |  | 
Wednesday, August 23, 2006 11:35:21 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Tuesday, June 27, 2006

I'm developing a set of server controls in ASP.NET 2.0 that use several JavaScript, image and stylesheet (CSS) files.  One of the problems with distributing controls is that you usually have to send along these files and tell the end user to install them in the appropriate directory.

Along comes ASP.NET 2.0 and the ability to embed resources right into assemblies and then access these resources via URLs.  My first impression is that this seems like a good idea but I'm wary because I've been burned by MS's good ideas in the past.  My main concerns are debugging and the effect this embedding has on caching. 

Caching

One of the problems with frameworks like ASP.NET is that they sometimes take you too far away from the underlying system.  HTTP and HTML is rather straight forward.  Embedded resources in ASP.NET call the the resources via URL's and  use cache headers to insure the browser caches the content correctly.  Also the output cache in the form of disk output cache is automatically used to cache these resources.  So these embedded resources should still allow a fairly performant solution.  My question is still whether this is as good as a plain static file and the caching IIS can perform on these files.  I still need to research this.

Debugging

One of the problems I've run into involves debugging.  When a JavaScript file is embedded and it contains an error, Visual Studio.NET 2005 will open a file dialog asking for the location of the file.  This is a pain as you lose the precious JavaScript debugging ability that we gained with VS 2005.  Is this behavior by design or is there something I'm missing in regards to debugging JavaScript as an embedded resource?  My tempo ray solution is to keep the JavaScript files in a static folder while I'm debugging and then switch them to Embedded Resources when I'm deploying the control. 

However on the plus side of debugging when you change the JavaScript file it is automatically picked up the next time you do a build.  The URL of the embedded resource is changed and thus the browser grabs the newer file.  However this has a downside in that you must stop the running project to make changes to the JavaScript file and then rebuild the project to have the changes show up.

I've found that the static file path is much easier for debugging.

 An excellent article that I've referenced for this post:

http://www.nikhilk.net/WebResourceAttribute.aspx

 |  |  | 
Tuesday, June 27, 2006 3:45:02 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Monday, June 19, 2006

Do you want to limit the imput of a text input (textbox) to valid date characters?  Here you go:

// START SCRIPT

function runKeyFilter(e) {
 if (e.srcElement.readOnly) return;

 var key_code = e.keyCode;
 var oElement = e.srcElement;
 //alert (key_code);

 try {
  if (!window.event.shiftKey && !window.event.ctrlKey && !window.event.altKey) {
   if (
     (key_code > 47 && key_code < 58) ||  // numbers on top of keyboard
     (key_code > 95 && key_code < 106)  ||  // number on numpad at right of keyboard
     (key_code > 36 && key_code < 41) ||  // arrow keys
     (key_code == 35) || // end
     (key_code == 36) || // home
     (key_code == 45) || // dashes
     (key_code == 111) || // forward slash /
     (key_code == 191) || // forward slash /                      
     (key_code == 8) || // backspace
     (key_code == 46) || // delete
     (key_code == 9) || // tab
     (key_code == 16) //SHIFT TAB
      )
   {
    e.returnValue = true;
    return;
   }      
  } 
 }
 catch (ex) {
  alert('Error Message: ' + ex.message );
 
 }
 // if we get here then we didn't have a number
 e.returnValue = false;

}  // end runKeyFilter()

//using the helper functions from prototype.js
Event.observe('|CONTROL|', 'keydown', runKeyFilter, false);  

// END SCRIPT

Monday, June 19, 2006 1:22:50 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Friday, June 09, 2006
If Jerry Seinfeld were a programmer he might ask "What's the deal with configuration files having to be in XML format?".  I just find them to be incredibly hard to read and decipher.  The problem with XML is that it's just so verbose.

Java has property files which may or may not be berrer. Ruby on Rails using YAML files.  These seem fairly reasonable.  One thing an XML file does however is let you show relationships and nesting of data.  So does the complexity of .NET require that the configuration files are also complex?  The configuration file seems to be a collection of serialized objects spat out at random into a file.  Is it a result of the everything must be XML crusades at the turn of the century?  Could the files be simplified?  Could we have seperate config files for seperate concerns.  Example, I go into the config file to change a setting and I typo.  My whole site (or server) goes down.  Is this expected behavior? 

So does the nature of .NET itself demand XML configuration or is this laziness on the programmers part to simply allow them to deserialize the configuration settings in the most convenient way (for them) possible? 

 |  | 
Friday, June 09, 2006 10:43:29 AM (Central Standard Time, UTC-06:00)  #    Comments [0]
 Thursday, June 08, 2006

IF you have a server to monitor that has many different applications, for instance an intranet server, and you want one error logging/reporting solution to rule them all then you've come to the right place.  It took me forever to find this information so I'm going to explain it. 

ASP.NET 2.0 comes with a feature called health monitoring (healthMonitoring).  This feature allows us to configure the monitoring and reporting of information related to ASP.NET.  Almost anything useful can be monitored but I was most concerned about handling server wide exceptions in a consistent manner.  Of course you should handle all errors/exceptions in each application if possible but sometimes this gets overlooked.  In Classic ASP we would route the errors (500's) to a certain page and capture them with the Server.GetLastError which worked just fine in Classic ASP.  However, in ASP.NET this doesn't work so well.  You lose the exception when you transfer to another application.  So you either have to store the exception s