Always Get Better

Archive for the ‘Web Programming’ Category

CommandEventHandler Event Won’t Fire for Button in ASP.NET Custom Control

Wednesday, September 24th, 2008

Problem: I created a custom control with a dynamic button and attached an event handler to that button.  When I run the control, clicking the button causes a postback but the event is not fired.

Solution: Changed the class inheritance from WebControl to CompositeControl.  Re-compiled and it worked like a charm.

FlexBuilder: Flash for Programmers

Thursday, September 11th, 2008

Since I’m not a designer (an obvious conclusion anyone will reach after taking one look at the design of this site), I’ve never had much use for the Flash development environment, nor any real desire to learn it.

Adobe FlexBuilder 3 provides an integrated development environment (Eclipse, actually) that allows programmers to build Flash applications. I was pleasantly surprised to discover this software, and found its brand of MXML to be very familiar coming from an ASP.NET background.

Stay tuned for updates as I learn more about this software. Have you had any experience with it? I welcome comments and suggestions – what should we watch for when working with this software?

JavaScript & Ajax Visual Quickstart Guide

Wednesday, August 13th, 2008

One day last year my client decided we needed to incorporate AJAX into their web site. AJAX was considered the big thing, and by not having “it” we were going to fall behind some of our competitors.

“What do you want to enhance using AJAX?”
“What do you mean? Just install AJAX.”

Ok. I’ve been doing a lot of work with JavaScript for years, including DOM manipulation and other Web 2.0-ish type trickery, but AJAX as a concept was something I had yet to explore. After reading resources available online, I decided to jump ahead a bit and buy a book on the topic.

I picked JavaScript & Ajax, Visual Quickstart Guide for a number of reasons.

  1. It featured a beginner’s look at AJAX
  2. It is part of the Visual Quickstart series – anyone who knows me will know that I love how professionally this series is put together
  3. It features a full-colour DOM object reference flowchart

I will admit this book is not the most comprehensive resource out there, for JavaScript or for AJAX. If I had wanted a more solid reference manual I would likely have sought out a book that focused solely on AJAX or solely on JavaScript. My trusty old tome Mastering JavaScript has always been a great reference, and I won’t get rid of it any time soon.

Although the title of the book is JavaScript & AJAX, the truth is this is a book about JavaScript. Right in the introduction the authors admit they simply added Ajax in this (6th) edition. Beginning the chapter on Ajax, we learn that the name of the book was changed to include Ajax in order to cash in on the success of the methodology. I won’t fault the authors for making that move – in fact I would consider a book about JavaScript to be incomplete nowadays if it did not include a discussion on Ajax.

I bought this book because of its practical discussion. The authors describe generic tricks such as adding dynamic dates and form validation to your site, something older books don’t always consider in much detail. Although the language itself hasn’t really changed since the 90s, the way we use it has. For that reason alone I like to upgrade my bookshelf to keep up with the current trends.

This book features a full colour reference chart for DOM properties. This may not be useful to people who like to use syntax-highlight and code completion software, but I still tend to write JavaScript in plain text editors, so any attribute I don’t know off the top of my head is handy to have at my fingertips.

In all, the authors have done a good job of bringing together a thorough primer for JavaScript. The book identifies itself as targeting beginner to intermediate programmers, an assessment I would tend to agree with. If you’re looking for a decent reference, easy to access, without a lot of jargon, this is the book for you.

ASP.NET: A potentially dangerous Request.Form value was detected from the client

Saturday, August 2nd, 2008

This error is caused by the presence of HTML in the fields returned by a form post.  In many cases, for example page management tools, you may want to allow your users to enter text formatted with HTML.  By default, ASP.NET doesn’t like this.

To turn it off, add ValidateRequest=”false” to the top of your aspx file.  This turns off validation of form results.

Honestly, I would rather if this property were available for individual form controls, because in my mind validation is still desirable overall even if one or two fields should allow HTML.  But there you have it.

What I Learned from MUDs

Friday, August 1st, 2008

The first bit of code I ever worked on was ROM 2.4, a text-based MUD server written in C.  At the time I didn’t know the first thing about programming, but through trial and error I was able to feel my way around the source code and slowly learn how the language worked and how to make the program do what I wanted.  Some experienced programmers called me the “snippet king” because I used a lot of pre-written additions to expand m game, but I see it as part of the learning process.  If I were to work on a MUD again, I now have the knowledge to do all of the programming myself – but if it weren’t for my baby steps back then I may never have become a programmer at all.

Text-based gaming is all but unheard of now that games like World of Warcraft and Everquest have taken hold.  In my opinion this is a crime because the worlds created through words were so detailed and so interactive that replacing them with pretty graphics makes for a much shallower experience.  It used to be possible to make life-long friends and really share interested, now the genre has been opened up to the lowest common denominator and there is so much swearing and name-calling that many older, more mature players don’t even bother.

I learned a lot of skills from my days playing MUDs that have helped me in my professional life:

  • Programming (obviously)
  • How to interact with others online
  • How to type very fast
  • How to write with personality
  • How to be thick-skinned (when people think they are anonymous, they are quicker to criticize and personally attack you, especially when you’re involved in content creation)

Replacing / Adding Line Breaks in GridView Text

Tuesday, May 27th, 2008

The GridView is a powerful control for quickly and easily displaying tables of data. However, a raw dump of information is not always good – when displayed by a web browser, normal line breaks are simply rendered as spaces.

For long blocks of text, it may be desirable to have your GridView insert HTML line breaks into your data. This can be accomplished either programatically or declaratively.

Programatically

As a programmer, my first instinct is to try to solve the problem using code behind. I add a RowDataBound event handler to my GridView and create the command this way:

protected void gvMessageList_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row;
if (e.Row.RowType == DataControlRowType.DataRow)
{
row.Cells[2].Text = row.Cells[2].Text.Replace(“\n”, “”);
}
}

Although it works, it has several drawbacks:

  • This solution uses a magic number to cause the compiler to replace the third column in the row.  If the structure of the GridView were to change, this function may break
  • This solution requires the developer to be aware of the final layout of the GridView and to make the connection between the control’s declaration and its logical code.

Use The Design

By far, the better solution is to simply declare the formatting changes in the same place as the GridView.  Using a Template field, I can add line breaks to my message by adding this:

<%# Eval(“Message”).ToString().Replace(“\n”, “<br />”) %>

More Information

This solution assumes the contents of “Message” are not null.  For more information about this technique (including how to deal with null values), I recommend the ASP.NET message boards: http://forums.asp.net/p/1027728/1403884.aspx

Blow Out the Candles for Spam’s Birthday

Saturday, May 3rd, 2008

Kudos to this article for acknowledging MUDs as the source of the term “SPAM”: A very unhappy birthday to spam, age 30

Now that spam has been with us for 30 memorable years, let’s take a moment to think of all the great things spam does for us:

  1. Enlarged lower members
  2. Enhanced “motivational” drive
  3. Pleased partners
  4. Cheap pharmaceuticals (like aspirin, of course)
  5. Lonely ladies with web cams
  6. University degrees for the masses
  7. Winning notifications for lotteries we didn’t even know we entered
  8. The opportunity to help the families of political victims retrieve their relative’s wealth, and share it with us
  9. Quality Rolex watches at amazing discounts
  10. Escape from debt

Not to mention it has become Nigeria’s chief export.


SEO Powered by Platinum SEO from Techblissonline