This Damn Thing Should Work

Wednesday, June 22, 2005

ASP.NET Date Formatting

It never fails - everytime I want to format a date any way other than the standard MM/DD/YYYY, I always have to look it up. I guess it's infrequent enough that it doesn't stick in my brain - I have no idea why I can remember obscure IP Addresses and Family Guy lines but I can't remember these...

This is a decent resource for this stuff - doubt it's exhaustive but its been good enough for me...

ASP.NET Data Web Controls Kick Start - Companion Web Site

This one is a little more complete - sans examples though:

http://www.riderdesign.com/articles/displayarticle.aspx?articleid=5

Tuesday, June 21, 2005

Hanselman's List

This appears to be an excellent list of tools for developers...

ComputerZen.com - Scott Hanselman's Weblog - Scott Hanselman's 2005 Ultimate Developer and Power Users Tool List

Monday, June 20, 2005

ASP.NET and HTML/Plaintext Emails

Here's the issue - we built a mass emailer (I know I know - contributing to the problem, blah blah) that we hooked up to a WYSIWYG HTML editor. Client generates her newsletters every month and sends em out.

I'm using ASP.NET, so I use the System.Web.Mail namespace and the MailMessage object to send out the emails, formatted in HTML. Everything works fine in testing, and we're all happy.

Then a few reports trickle in (along with example emails) of the text of the newsletter with all the text glommed together. I gathered from the people reporting this that they were using plaintext email readers. Basically the tags were being stripped and the email was sent out with what was left (which was a big glob of text).

My first reaction was surprise - I remember the days of plaintext email readers and getting an HTML formatted message usually consisted of the "this message is of Content-Type HTML" etc. that displayed a not so great looking version of the email - but you knew it was HTML and that was the issue. These messages were different - they looked like normal email plaintext messages - but they were coming from an HTML formatted message.

After a sizable amount of digging, I found out that the System.Web.Mail namespace automatically creates a plaintext version of HTML formatted messages and delivers the email as "multipart/alternative" which allows the plaintext readers to ignore the HTML version. This was a footnote on a website somewhere - couldn't find any reference to it on Microsoft's site...

After some more testing, I found out that our WYSIWYG was generating its break tags as <br/> rather than <br /> . I did a batch replace before sending the email and suddenly everything worked fine.

Sigh...

Friday, June 17, 2005

ASP.NET, Javascript, and Server Controls

I've mentioned before that I'm a Javascript junkie - I find myself using it quite a bit. ASP.NET made it a little tougher in the sense that when using server controls, the id assigned to the control varies depending on the situation. In a normal situation, the id assigned is used. But when used in a user control, the name of the user control is appended to the beginning of the id. As long as you understand these rules, its possible to get it all to work.

Today I found this - which looks like it takes some of the guesswork out by using the ClientId attribute of a server control...

Accessing Server Controls Using JavaScript

Wednesday, June 08, 2005

Unicode and ScrollKeeper

Another nagging issue solved - although it reintroduces a previously solved nagging issue - sigh.

A few months ago, I was getting complaints from clients that had lengthy forms that when I used an autopostback from a dropdownlist the screen would return to the top of the form rather than where they were. Some digging quickly showed that this was a known ASP.NET issue, and there were a few ways around it, all hacks. Microsoft gave their own version with SmartNav, but all the discussion said it sucked, so I looked around and found an article (http://philiprieck.com/blog/archive/2004/02/11/ScrollKeeper.aspx) that I tried and it solved the issue. I was impressed because it was really easy to use.

Fast forward a few months. I've used the Scrollkeeper code in a number of projects and have had no problems with it. But with this one site we just launched, everytime you posted something with Unicode characters in it, it lost the unicode and replaced it with a ?. I tried EVERYTHING I could find on encoding issues with ASP.NET, the editor we were using, anything and everything. Probably spent close to 10 hours trying to solve it. Finally, today, I figured out that it was the ScrollKeeper code that was causing the issue. As soon as I took it out everything worked fine.

You might be wondering why I didn't try that earlier. The answer is that basically it has always worked before.

Cripes...

Friday, June 03, 2005

JavaScript Strings

This is a pretty useful resource for people playing with strings in Javascript...

IE 6.0 - JavaScript - Strings

Wednesday, June 01, 2005

Truncated Emails

Here's an odd one - I developed a somewhat sophisticated hack of a system for one of our larger clients to generate emails. Basically it hooks a large user database (complete with associated order information) to a WYSIWYG editor and template system so they can send out customized, mail merged emails. It works pretty well. But the issue at hand was reports from users of RoadRunner (specifically the NYCAP region) were receiving truncated versions of the emails - the text of the email would simply cut off at some point in the email - not the same place every time either.

I tested the emails on every email server I could find - including RoadRunner (but of the TWCNY region) and they all worked fine. The reports continued, and all were from users of the NYCAP RoadRunner. So I did some more digging and found one resource :

Truncated emails with tcp.sendMail

which humbly suggests at the bottom of the post that some email servers will truncate emails that have more than a specified number of characters per line. The emails I have been sending out are big blobs of HTML I get by screen scraping a page generated by the system (for the mail merge). Never would have guessed that one.

I solved (hopefully) the issue by manipulating the scraped string and adding vbCrLf's after paragraph tags and closing column tags (</td>) ...

Sigh...

Client Side Stuff

I'm a Javascript guy. I've been doing Javascript junk long before I'd even heard of Active Server Pages. Consequently, the nifty Javascript tricks I've been using for years I want to use - but I constantly find myself at odds with the way the .NET handles client side code.

Today's issue was running some javascript commands that needed to fire either onLoad or at the very bottom of the page - with the various user controls I'm using in this one project, I couldn't get the script low enough on the page. But then I discovered these options:

ASP.NET Client-Side Script FAQ

which detail a whole mess of options for dropping script in various places on a page regardless of other objects. Quite helpful - definitely solved my issue...