When Visual Studio 2005 was released together with ASP.NET 2.0, the web project model was totally changed from the ASP.NET 1.x model. It took some time for me to get used to it, and in the beginning I didn’t like it much. Apparently, I was not alone and Microsoft got a lot of mail from developers who wanted the old Web Application Project (WAP) model back. Visual Studio 2005 Service Pack 1 then reintroduced the WAP model.

I never really understood why so many people wanted the old model back, because it has some serious inconveniences. My guess is that almost all of the people who wrote Microsoft wasn’t web developers to begin with, but maybe had a past doing Windows Forms to which the WAP model bares many similarities.

No change 'n review

Old school web developers like to make a small change and then see how it looks and continue to do so an awful lot of times. The WAP model doesn’t allow you to do quick changes and review them at once. You first have to compile the entire project and that can easily take 30 seconds for larger web projects. At work, we have a web project that takes 3 minutes to build.

That quickly gets very annoying and is just a waste of time. The Web Site model does not have that problem.

No quick ‘n dirty editing

In the WAP model, if you don’t have Visual Studio you cannot change anything but the layout and that is really annoying. When I’m away from my Visual Studio and finds something I want to change, then I’m not able to. The Web Site model on the other hand allows me to change anything I want using only Notepad and the build-in FTP capabilities of IE.

Annoying deployment

The initial deployment in the WAP model is easier because there are fewer files to be FTP’ed to the remote location. But if you want to make a small change and deploy it, then you have to FTP the dll file which can be several hundred kilobytes. Now you think: how can that be a problem on your super broadband connection? Well, it can if I’m doing small changes an awful lot of times and need to upload them to review them. Then that extra 5 seconds of upload time just get on my nerves.

In the Web Site model you just upload the file you changed. That’s 2 kilobytes versus 200 kilobytes.

What I’m trying to say is, that I don’t understand the popularity of the WAP model…

If you have added some ASP.NET validators to a webform, you might want to run them before hitting the submit button. In BlogEngine.NET we need to run the validators when a new comment is about to be added, but because it is using AJAX to post the comment we don’t submit the form.

The form is only used to take advantage of the validators and the server controls such as TextBox and they are still needed for clients that don’t support AJAX. What we needed was a way to validate the page from a custom JavaScript function.

Whenever a validator is added to a webform, a reference to the WebResource.axd JavaScript file is added as well. In here is all the mechanics used to do client-side validation and a lot of other useful things. It holds a function called Page_ClientValidate() which runs all the validators and returns true if all validators validates, otherwise it returns false. It also makes sure to show the error message of the validators that fail.

You can use it from within a button by specifying the onclick client-side event like so:

<input type="button" value="Save" onclick="if(Page_ClientValidate()){DoSomething()}" />  

If the Page_ClientValidate() function returns false, nothing happens and the error message of the individual validators that failed is shown. If it returns true, then everything validates and you can proceed. Just remember to do a manual server-side validation as well.