Saturday, December 15, 2007

Interesting MCPD Exam Question

Going through some MCPD practice exam questions, I ran into an interesting question I wanted to share. This questions highlights a programming philosophy in .NET coding that is encouraged by Microsoft.

Here is the question:
Click to expand any image.

question not avaiable


The choices for answers are:


choices not available


Now on a first look, it seems like the correct answer is the first choice since indeed the code does satisfy the requirements. However, the correct answer is the one highlighted. Here is why:


explanation not available


Interesting huh?

Wednesday, December 12, 2007

ASP .NET Model View Controller

Last week on Monday, Dec 3rd, I went to an event hosted by ladotnet.org about the new ASP .NET Model View Controller (MVC) framework. The guest speaker was Phil Haack who is currently at Microsoft working on MVC. Overall I think the concept behind MVC is great. The framework looks promising. However, there are some drawbacks which I will just mention. Below is a summary of major points gathered from the meeting:
  • MVC framework is built on the idea of separating the view and controller parts.
  • MVC is not a replacement to WebForms but just an alternative.
  • MVC pages cannot contain controls that require a postback.
  • ViewState does not work with MVC.
  • MVC allows for using "REST"-like URLs (friendly looking URLs).
  • MVC generates cleaner HTML code that does not require ID munging.
  • In the MVC framework, URLs map to actions not pages.
More information on MVC should follow later as I test it and learn more about it.

Saturday, December 8, 2007

Modifying CSS Styles with JavaScript

I recently came a cross problem at a client where I needed the page content to change upon a button click before the page is posted back. For example, imagine you have a page used to upload files. You want the page to display something like "Your file is being uploaded" right when the user clicks the upload button. Then the page is posted back while the desired message is displayed. The solution I came up with utilized JavaScript to modify the Cascading Style Sheets, CSS, of the page and then post.
The solution was as simple as adding multiple wrapping div's around the content. This could actually be done with only two div's but for my page I need three. The div that had to be shown when the page is first requested had a default CSS Display property value of "block." The div that was to be shown after the user clicks a button had Display value of "hidden." In the code that executed following the button click as shown below, one div is being hidden, one is modified to be shown, and lastly the page is posted. The JavaScript code I had was similar to the following:


function btnClick()
{
document.getElementById("initialDiv").style["display"] = "hidden";
document.getElementById("secondDiv").style["display"] = "block";
document.form1.submit();
}