For those who have not yet seen Stackoverflow or Twitter’s Notification Panels. You are missing out.
It’s a neat way to display messages to your users without being too intrusive.
There has been quite a lot of noise regarding ASP.NET MVC with the release of version 2.0. Not to mention the amount of noise the JQuery community has been making. This usually follows by the line, “JQuery is the best thing since sliced bread :)”
Since ASP.NET MVC is not a replacement for ASP.NET Webforms, let’s explore how we can incorporate a notification bar in ASP.NET Webforms.
You can use the following method with any JQuery type notification panel/bar but for this sample grab the Notify Bar from Dmitri Smirnov.
1. Include the jquery.notifyBar.css and jquery.notifyBar.js in your master page
2. Add a static class to your project e.g. (Note the use of extension methods here)
/// <summary>
/// Notification Helper
/// </summary>
public static class NotificationHelper
{
/// <summary>
/// Show Message
/// </summary>
/// <param name="message"></param>
public static void ShowNotification(this System.Web.UI.Page page, string message)
{
page.ClientScript.RegisterStartupScript(typeof(Page),
"notificationScript",
"<script>$(function () {$.notifyBar({html: '"+message+@"',delay: 2000,animationSpeed: 'normal'});});</script>");
}
}
Now in your Pages you could just call the
Page.ShowNotification(“Hello World!”);
c3b90612-d552-4373-b120-db4890ca89de|0|.0
The most annoying part of getting to a site is the bit where you have to register. It’s annoying having to complete a 50 page essay just to become part of the community. Since now, there have been numerous attempts to provide a single sign on facility and the only one worth exploring for me was RPX Now.
Let’s take a look at Stackoverflow and how Jeff Atwood and his team have just nailed the registration process.
Clicking on the Log In button will take you to a page that will ask you which provider you wish to sign in with. In my case, let’s use MyOpenID.
This will take you to myopenid.com and ask you to verify yourself and WHAM! You can associate your id with Stackoverflow and registration is complete. How did Jeff and his team manage this? I don’t know but it’s magic!
The one way to implement this is to use RPXNow and grab the RPXLib.
First up is to understand the process of RPX and how it will interact with your site. To break it down into simple bits.
1. User clicks on your log in link.
2. User is asked to choose a provider, be it twitter, google or openid.
3. User enters their credentials and gets passed into a void
4. Moments later the user is passed back to your page with a token. You can utilize this token to get details about the user.
1. User Clicks on your log in link
After following the simple directions on RPX Now, you should have a bunch of javascript and a link that was given to you.
<script type="text/javascript">
var rpxJsHost = (("https:" == document.location.protocol) ? "https://" : "http://static.");
document.write(unescape("%3Cscript src='" + rpxJsHost +
"rpxnow.com/js/lib/rpx.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
RPXNOW.overlay = true;
RPXNOW.language_preference = 'en';
</script>
<a class="rpxnow" onclick="return false;" href="https://mvcwebshop.rpxnow.com/openid/v2/signin?token_url=''>Sign In</a>
4. Moments later the user is passed back to your page with a token. You can utilize this token to get details about the user.
The user is passed back to your control and you are given a token to query the rpx service with.
/// <summary>
/// Sign In
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
[HttpPost]
public ActionResult SignIn(string token)
{
return View();
}
Remember, to include the token as part of the parameters of the Action. Also, note the use of the attribute HttpPost. This tells asp.net mvc that this action will only respond to Http Posts.
Using this token and RPXLib, we can very easily query the service to get the user details, like so :)
/// <summary>
/// Sign in the user
/// </summary>
/// <param name="username"></param>
/// <returns></returns>
public bool SignIn(string token)
{
RPXLib.RPXService service = new RPXLib.RPXService(new RPXLib.RPXApiSettings("http://rpxnow.com/api/v2/auth_info", "youruniqueAPIKey"));
try
{
RPXLib.Data.RPXAuthenticationDetails userDetails = service.GetUserData(token);
return true;
}
catch (RPXLib.Exceptions.RPXAuthenticationErrorException ex)
{
}
return false;
}
Remember that when setting up RPXNow, you can point it to your local development server (http://localhost:1234/SignIn/).
Have fun with it
f9622065-c1f2-4137-b944-311406cf2ffd|0|.0
You might have run into this problem, or you might not have, but this was stumping a lot of people all over and when we finally came to the solution, it all made sense.
Next time you run into the issue, make sure it’s not an issue where cookies are not passed. Either by a load balancer, or similar piece of software/hardware. You will save yourself a lot of pain!

ff719b9b-d8fb-4b95-a553-410e3cb3133c|0|.0
First we will need to setup the JsonResult controller action.
///
/// Get Models
///
///
///
public JsonResult GetModels(string id)
{
JsonResult result = new JsonResult();
var filteredModels = from model in homeViewModel.Models
where model.MakeID.ToString() == id
select model;
result.Data = filteredModels.ToList();
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;
}
This method now gives us the ability to use the nifty $.getJSON jquery call.
The signature for the call is as follows
jQuery.getJSON( url, [ data ], [ callback(data, textStatus) ] )
Given that we have setup 2 Drop Down Lists, one for Makes and the other for Models, like so.
we can include the following bit of jquery
//Hook onto the MakeID list's onchange event
$("#MakeID").change(function() {
//build the request url
var url = '' + "Home/GetModels";
//fire off the request, passing it the id which is the MakeID's selected item value
$.getJSON(url, { id: $("#MakeID").val() }, function(data) {
//Clear the Model list
$("#ModelID").empty();
//Foreach Model in the list, add a model option from the data returned
$.each(data, function(index, optionData) {
$("#ModelID").append("" + optionData.Description + "");
});
});
}).change();
CascadingDropDownList.zip (365.72 kb)
8e9ecd79-e81d-45a1-bcfc-0f862fa90a2b|0|.0
It’s difficult to remember the principles of the paradigm when you are bombarded with deadline after deadline and you just need to take a step back and realize that.
class, instance, methods and inheritance, abstraction and encapsulation they ring a bell don’t they? They are the principles of object oriented programming, the paradigm most of the programmers use nowadays.
Digging through my own code, I see names like “Entity” and “RenderableEntity” and you know, I kept thinking, they aren’t truly descriptive and looking at their name, you cannot determine what their functions or properties are.
When developing an API, I like to keep in mind that the consumer of the API, should not need to have a look at any documentation to understand how the API works, it should just come naturally.
Let’s have a look at an example from the .NET Framework
DirectoryInfo directoryInfo = Directory.CreateDirectory("NewDirectory");
directoryInfo.MoveTo("c:\\NewDirectory");
I’m not too fond of Directory.CreateDirectory, I would’ve had Directory.Create(…), but you can determine that Directory would have a Create method inside of it, as well as returning some kind of information related to the directory that just go created.
I hardly ever have to open the MSDN documentation, the reason for this is clean design of the BCL (Base Class Libraries).
So, next time you decide to write a library of some sort, make sure that it’s intuitive and that you aren’t the next victim of the Daily WTF.
e4181b41-6726-44d5-95c8-72a24ad637fd|0|.0
Posted by
pieterg on
3/23/2010 8:02 AM |
Comments (23)
The IDE has an awesome new splash screen and has totally been reworked in WPF (Windows Presentation Foundation)
Generate from Usage allows developers to quickly generate code from definitions
The dynamic keyword, who better to explain this than the wonderful post by Scott Hanselman.
Here are the screenshots, just to show you what the behaviour is like for a method that is being called that does not exist. This exception is thrown at runtime as the compile time checking has passed.
Call Hierarchy View
This is a pretty cool IDE feature as it gives you a quick indication as to where a call to a method is begin made and from where. It allows for easier navigation and understanding of the code.
That’s pretty much it for now, stay tuned for more quick bits on the IDE!
407fce1b-1048-4946-8743-edca16d4c2d9|0|.0
Posted by
pieterg on
3/22/2010 7:43 AM |
Comments (11)
From time to time I think about the exciting and fantastic industry we are in. I also think back to when I just got involved in the community where it was the never ending pursuit to find more Anders Heijlsberg videos. A Hero in the software development world!
We get to play with so many different technologies such Silverlight, Windows Presentation Foundation, Windows Workflow and so many more. We get to do so many various things such as develop games, enable companies to work more efficiently and easier, code applications to make our lives easier and just code for the sake of writing a hello world application in a language we just stumbled upon.

The other awesome thing about our industry… the community. We have heroes such as Scott Hanselman, Phil Haack, Rob Conery and Jeff Atwood, just to name a few.
We get to be creative, solve problems and best of all, do it in teams or on our own. Listen to music while we are doing it!
2ffb250c-c1ef-4767-a01a-486a7fa723a8|0|.0
It’s extremely important as technologists that we keep up to speed with some basic algorithms and principles of computer science. It’s difficult when you are bombarded with all kinds of new technologies to go back to the basics now and then.
Igor has a new take on solving problems and it makes use of some computer science concepts such as recursion and loops. It’s called RoboZZle and it’s a puzzle game coded in Silverlight.
RoboZZle is an online puzzle game that challenges you to program a robot to pick up all stars on a game board. The game mechanics are simple, yet allow for a wide variety of challenges that call for very different solution approaches.
The game is well put together and the controls are simple enough. Although, I thought that in the beginning the buttons were supposed to be dragged and not clicked and dropped onto the empty method call.
The reason for highlighting this game is the amount of developers that just seem to skip the basic concepts and when it comes to solving a basic problem.
This highlights an entry made by Jeff Atwood of Coding Horror and now more recently the amount of boom of Stack Overflow.
dedc0fa6-40cc-47d7-af67-88c2b27798a3|0|.0
Never trust user input!
This week at MIX10, Phill Haack had a presentation on what is new with ASP.NET MVC 2.0. The following is a list of the new features in ASP.NET MVC 2.0 from Scott Guthrie’s blog
I have recently been tinkering with an amazing validation engine in jquery from Cedric Dugas. I thought to myself, what an awesome idea it would be to try and minimize the effort of adding the validation engine to the Model Validation inside ASP.NET MVC 2.0.
The first step was to determine where the validation was taking place.
Inside of jquery.validate.js, I found the formatAndAdd function on line number 574. After the error message is constructed, I added the validationEngine.buildPrompt function which is a way for developers to utilize the nice looking prompt that is packaged as part of the plugin.
formatAndAdd: function(element, rule) {
var message = this.defaultMessage(element, rule.method),
theregex = /\$?\{(\d+)\}/g;
if (typeof message == "function") {
message = message.call(this, rule.parameters, element);
} else if (theregex.test(message)) {
message = jQuery.format(message.replace(theregex, '{$1}'), rule.parameters);
}
$.validationEngine.buildPrompt(element, message, "error");
this.errorList.push({
message: "",
element: element
});
this.errorMap[element.name] = message;
this.submitted[element.name] = message;
},
Step two to determine where the errors are removed, when they have passed the validation rule.
I found an unhighlight function on line 259 of the jquery.validate script. This code doesn’t remove the error, but it does remove the highlighting from the control. I decided to tie into this piece of code by adding the closePrompt method from the validation engine.
unhighlight: function(element, errorClass, validClass) {
$.validationEngine.closePrompt(element);
$(element).removeClass(errorClass).addClass(validClass);
}
The final step is to initialize the validation engine.
on line 50, after the submit button was clicked, we will initialize our validation engine.
if (validator.settings.onsubmit) {
$(validator.currentForm).validationEngine();
Here is the sample code. To utilize this code, all you will need to do is get the latest version of the Validation Engine and replace the jquery.validation.js with this one.
jquery.validate.js (48.89 kb)
ValidationDemo.zip (391.38 kb)
Update : An Update from the Validation Engine guru over at position-absolute now removes the box when you click on it, if it’s in the way.
bef5dfa6-87ae-403f-8410-056152b856d8|2|4.5
Posted by
pieterg on
3/16/2010 8:13 AM |
Comments (15)
What is a bad way to determine whether your software works?
Do you have to click through every single button on every single screen to make sure that something isn’t broken? And if it breaks, do you know what went wrong and where?
If you answered yes and then no, then you probably haven’t written unit tests for your code as most of these issue can be reduced.
Unit tests improve design and and ensures that as a developer, you are thinking about decoupled objects serving a single responsibility and thinking more along the lines of writing testable code.
I am not saying that Unit tests eliminates all bugs or issues. It just reduces them significantly.
What Unit Testing frameworks are there for us to use?
There are quite a couple as we can see from Wikipedia.
I just tend to use the Visual Studio unit tests.
44c688de-9097-4356-8501-f09099dceda0|0|.0