Response.Redirect not working (I'm looking at you SmartNavigation)
Whew. It has been a crazy two weeks on this project, and it all culminated with a nasty error where Response.Redirect was on the fritz. This one tore me up before I was able to figure out what was going wrong.

Basically I was doing a Response.Redirect on a page, and in Dev and Test it worked like a charm. Even after I moved it to production it worked for a while. But then the horror occurred. The response redirect suddenly would simply post back to the same page - no redirect at all.

I was able to narrow it down to the response.redirect fairly quickly, but I assumed it wasn't playing nice with some server setting in Prod that wasn't switched on in Dev or Test.

Well - I am not entirely convinced that some switch in IIS didn't get flipped, but quite frankly going down that rabbit hole wasn't getting me anywhere, and the client was waiting.

So I looked at all the opages to see how this one differed. Turns out this page was the only one with SmartNavigation turned on. So I set SmartNavigation to false, and voila.

Hope this tip helps some frustrated soul out!

EDIT: I have learned more about this error. See here for details.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
How to make your ASP.Net label multiline (how to wrap text in your label)
First off, sorry for the absence. Things got a little busy in life as well as work. Not to mention having to get up to speed on 2.0 in a big hurry. All good things, but it left less time for fun stuff.

With that said, I want to offer a little tip to help with formatting your ASP.Net pages. Getting a label to be multiline within a set width. Now many of you know this trick, but I always have to re-remember the trick every time I need it, so this post can be a reference for you as well.

The trick is actually this - Don't use a label. Use a textbox instead. Since all the controls inherit from the same base class, the text box and the label are very similar anyway. But only the textbox has the multiline capability.

Once you have the textbox on your page the trick is to make it look like a label for the end user. To do this you need to set the following properties (This is the part I can never remember):

Wrap = true; (obviously)
rows = {some number greater than 0} (I use the rows property rather than the height property as it tends to be earier to get the formatting right)
ReadOnly = true (makes sense, right)
TextMode = multiline (or there no real reason to wrap the text...)
BorderStyle = None
BorderWidth = 0

Those last two are actually VERY important, and here is why. They get rid of that pesky border that you see around text boxes. That border is a common visual signal to the end user that says "ENTER INFO HERE!". If you leave the border up expect a lot of phone calls from folks saying "The web page is broken. It won't let me enter text."

So use this in good faith. More controls soon. Even my first 2.0 controls.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Microsoft Webcasts on ASP.Net 2.0 and SQL server 2005
Get on over to Microsoft and watch some of these ASP.Net 2.0 webcasts. The content is great, and it has helped me get up to speed in 2.0.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
ASP.Net 2.0 error 'The Sitemappath 'Web.sitemap' cannot be found'

This was a frutrating one, and since 2.0 is so new, I couldn't find anything about this on the web.  But eventually, I figured it out...

The answer is that you can not specify the web.sitemap in the data source controls.  It is actually the default, and ASP.Net 2.0 selects this automaically.  If you try to tell it specifically to look for the default it has an stroke.  Hope this helps.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
SQL Server 2005 and XML Presentation
If you are going to be in the Winston-Salem North Carolina area on November 5th, 2005, then come and hear me give a talk on SQL Server 2005 and XML
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Microsoft e-Learning
Free courses are still available here.

But they will not be around for much longer. If you are scheduled to take a beta exam, I imagine these course will be VERY useful for you. Go there now - it's free.

One caveat. The course is only available for 30 days after you sign up. So don't sign up for all of them at once.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Pro ASP.Net 2.0 in C# 2005 by Matthew MacDonald and Mario Szpuszta from Apress
As I am sure everyone who takes the time to read this article is aware, in November Microsoft releases a huge upgrade to their developments platform, VS2005. (There is also some other releases in this time too, but that is for another article.) Part of that release is a complete reworking of the ASP.Net platform. Not that there is anything disastrously wrong with 1.1, but if you have developed with it for any amount of time, you know where its weak points are. That is, there are not an inordinate number of bugs per-se in ASP.NET, but there are functions that are difficult to implement. I am thinking specifically of Master Pages, Skinning, Dynamic Data Controls, Web Parts, etc. Thus, ASP.NET 2.0 is designed to speed up the development process.

But a better development platform only speeds up development if you know the tools available, and getting learning the tolls in ASP.NET 2.0 is no small task. While much of the framework’s basics haven’t changed, there are a whole slew of new controls to learn about; not to mention how to build portal using web parts, or how web site administration works. While this process is MUCH easier than learning how to build functions by hand (your only option under earlier versions), you still have a learning curve to work through; and fast. We have all seen it before: A year from now when companies finally switch to 2005, they all want developers with 3-5 years experience. So now is the time to learn. (Better still, do a 2.0 web site for a friend or a charity for free. It is great experience, and you can truly say you have been working with 2.0 since it was in beta.)

Always for me the question is: how best to learn all that you need. I am a book reader, but I like books that have examples – complete with source code. I also prefer books that are comprehensive. If I am going to drop the requisite $50 - $60 for one of these tomes, then I prefer the authors to err on the side of too much information. I can always skip the chapter if I feel like I have the topic down. Pro ASP.Net 2.0 in C# 2005 by Matthew MacDonald and Mario Szpuszta is the book for the new version. It is a hefty tome, and it took me a few weeks to get through it. But this is good, ‘cause these guys didn’t skimp or skim. Better still the examples are just as comprehensive, and all the source code is available on line.

The book is directed to a specific audience; that is to say, they wrote this with the expectation that the reader has a base knowledge of web development, and specifically a working knowledge of ASP.NET. (They direct the newbie to other resources.) But they do not assume that since the reader has used this technology before that they know the why’s of a technology, as well as the how’s. This was a pleasant surprise. I find that if I get a glimpse under the covers of a technology, it helps my understanding in the long run. This book has some great examples of this behind the scenes documentation. For example, this book has one of the best explanations of the Kerebos Authentication process that I have seen outside of a Windows Server book. It is worth the price of admission for this alone (I think developers know far too little about this side of development, but that too is another article.)

So I have a new go-to reference that will sit on my shelf next to where I work. You know what I mean. There is always that one book that you reach for when you run across a thorny problem. One that you go for even before the internet, just because you know where to go to find the info you need. It is chapters like the integration of JavaScript and ASP.NET 2.0, that I know I will use again and again. Oh yeah! It’s also available in e-book form. So I don’t have to lug the book to my on-site contracts. Just one last touch from the guys at Apress. I would definitely recommend you pick this one up.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
How to scrape a website without being stumped by 999 errors
Web site scraping is a great tool, and it is so easy in .Net. But there are some snags, especially if you are trying to build a robust system that can run unattended. One of these problems are web errors like '999 web site temporarily unavailable.' .Net views these errors as fatal and boom you are out of the program. Now you can catch them then recall the mentod, but this recursive action can eat up memory very quickly. There is however another way:

public static string ScrapeURL (string URL) {
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
HttpStatusCode code = new HttpStatusCode();
HttpWebResponse resp = null;

try {
resp = (HttpWebResponse)req.GetResponse();
code = resp.StatusCode;
} catch(WebException err) {
return null;
}

string strResult;

using (StreamReader sr =
new StreamReader(resp.GetResponseStream())) {
strResult = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return strResult;
}

Then all you have to do is call this procedure in a do..while (response !=null) loop and away you go. Notice that you avoid stacking up multiple calls because all we are doing here is ignoring the WebErrors.

You can also get more specific and use the code = resp.StatusCode in a case satatement to different things based on the specific HttpWebError. (ie you may want to react to a 404 error differently than you do for a 999 error.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Learning Perl
Right up front, the authors of this book state that you really should have done smoe coding befor in order to get the most from this book. But with that pre-requisite covered 'Learning Perl' is a fun and information dense learning tool. Not to say that you can’t do it if you have never coded before, but it will be more of a struggle. Luckily I am familiar with how to code (note: there may be those who strongly object to this statement), and so this book turned out to be a fabulous resource.

Coming in at under 275 pages, the book doesn't waste time in getting down to what you need to know. I am a self-learner, and I was constantly amazed at the end of each chapter at how much we had covered. Given such information rich text, you might imagine it to be a little dry. Not so. The book exhibits a quirky, geeky sense of humor. And be warned; it uses footnotes extensively. While that may not be your bag, I found the footnotes made the book more like an internet browsing experience (or an author who uses excessive parentheses - like me). I treated the footnotes like a link to more detailed and in-depth information.

I do have one small beef. The authors assume that you are a UNIX programmer. There are numerous references to UNIX arcana, which you are supposed to just know. Phrases like 'If you want to make a Perl program [..] like the utilities cat, sed, awk, [..] and many others..' mean nothing to me. Furthermore there is little (a couple of paragraphs) to explain how to get Perl up and running on a Windows box. Now, I can easily overlook the little Microsoft digs, but I think more of an effort could have been made to reach out to the 'other side'.

So now, I am building my own Perl library. I love the functionality it gives me. Once I figured out how to call programs from other web platforms I was one happy camper. It is surprising how well it integrates with Windows. All in all, the time spent with this book was well worth it. Mainly the book provided a quick and comprehensive introduction to a powerful and flexible language. Thankfully the authors took a difficult subject and made it easier with their light in tone / heavy on the info style. Check it out.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
New Article in 'Building Custom Controls' Series

I just posted the first article in my series 'Building Custom Controls'.  I learned a great deal about the process from this simple control.  Not the least of which was the inherent challenges of building controls that do the bulk of their work at the client.  I also got some good ideas about what kind of control to tackle next.  If you have a suggestion let me know here. 

In the meantime, I am working on a post about adding and testing custom controls.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Learning Resources
OK - Confession time.

I am new to the coding game. I strted this after an aborted "career" in Accounting. I found myself spending more and more time slicing and dicing the data in SQL. I liked it, and I hated accounting, and so I made the leap. This was after the bust of 2000, so you know I was ready to leave my previously chosen field.

But what this mean is: I feel like I am lacking some base fundamentals of the field. I can tell you how Depreciation works, but I am not able (yet) to discuss the intracasies of memory buffers. My response is to go to the web, but most of the resources there are to solve a particular problem. However, I have found a couple of great theory resources that I use daily. I just wanted to share them with you guys:

MIT Open Course Ware - Quite possibly my favorite resource. Who'da thunk you could get an MIT education for free. (You don't get the sheepskin, but what they hey....)

InformIt Blogs - Another source I go to every day. You need to poke a little deeper to get to the theory, but its in there.....

Joel - I am betting that most of you know about Joel. He does tend towards more management issues, but there are some excellent discussions of theory in his blog as well.

So, if you are in my boat, what resources do you have for these more general concepts about programming as an engineering dicipline?

There - that wasn't so bad a confession was it?

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Namespaces for Classes
So I am working on the self-validating text box, and the first issue I ran across was the namespace naming convention. Just what the heck should the namespace be for these controls? I finally settled on something similar to the Microsoft convention – At least I know it works.

MyCompany.Web.UI.WebControls

Will I ever have a need for classes under my web namespace that are not web controls? Well – I hope so. I have in mind a web counter since so many of my customers request one, but lets save that for another day. In the meantime I hope to keep my namespaces as flexible as possible.

In the back of my mind, I knew that I would only build the dll at the webcontrol level. This way I won't dump a whole bunch of 'extra' functionality that the project doesn't need. Of course this means more maintanance.

How do you guys typically do this?

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Best Text Editors
Besides the obvious answer (Visual Studio) what do you folks use as text editors? I just downloaded two Vim and UltraEdit. I plan on trying to use Perl some in Windows, but I use the Text editors now for HTML development.

A tool I have really come to like (if you have Firefox) is the "view formatted source" plug-in.

This has proven to be an invaluable tool for viewing HTML source. I just wish I could save a page and edit it locally with this tool. If I had the time I'd write that myself.

So give your fave text editor a shout out - tell me why you like it.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Building a control library

There are so many times when working on a project I find myself thinking - “I just did this exact same thing on my last project.”  So I do the old cut-and-paste routine, and move on.  While it ain't best practices, it has served me well enough.  Then the inevitable happened.  A client requested a change that closely mirrored a change in a control that I was working on for another client.  And I began to seriously look at creating a control library so I would only have to make the change once.

So, over the next few months I plan on building some controls, and writing some articles about it.  Since I mainly do web-programming, I plan on starting with web controls.  I am probably going to start with a self validating text box, since this is the problem that started me down this train of thought.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
'Line 1: Invalid syntax near' in ASP.Net
The other day while working on an ASP.Net website with some simple ADO.Net CRUD functionality, I was getting the most frustrating error.

"Line 1: Invalid syntax near 'spMyProcedureName'." But I ran the stored procedure in Query Analyzer, and it worked fine.

Typically my response is to go to the web, but a search on the error message turned up only people with the same question - and no answers that worked for my situation.

After much searching through code, and admittedly some yelling, it finally came to me what the problem was: I had not set the command type to 'StoredProcedure' on the command object.

Dang literal computers.
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati