IronRuby in Action by Ivan

Yet another friend of mine is writing a book. After Keyvan with his "Professional Visual Studio Extensibility", today Ivan Porto Carrero announced his book IronRuby in Action.

It will be published by Manning and, as always with them, a Early Access Preview is available.

Congratulations Ivan for your first book!!

 

Running Challenge for .NET developers

Spring arrived, days are getting longer and I started jogging after work again (of course, with my Nike+iPod gear).

I also found out that Vito Arconzo, a .NET developer in Italy, also started running with an iPod, so I decided to set up a running challenge, and see how many .NET developers out there are using this geeky stuff.

The challenge is named "Train for the UGIALT.net meeting", will start tomorrow, May 15th, and the winner will be the one that runs more kilometers in 30 days, before the UGIALT.net conference that will take place on June 14th.

If you want to take part in this challenge, just send me a email with the email address you used in your Nikeplus account, and I'll add you to the challenge. Or subscribe to the challenge yourself going to the Nikeplus site.

Technorati Tag: ,,
 

How to manage ASP.NET validation from Javascript with jQuery

Validators are a great part of the ASP.NET framework: they provide a standardized and easy way to add validation to form fields. But even if the framework provides different kinds of validators, there are so many different validations patterns that sometimes you have to write custom code to match your specific requirements.

I wrote a post a few months ago about how to write a custom validator for a Checkbox list, but I was dealing with a completely new validation pattern. But what if I only want to enable the validation of certain field based on certain conditions? Or if I want to validate based on an event that is not the OnChange event of the form field? And all of this while keeping the standard validation logic?

If the condition can be determined in the code-behind it's easy:

//Disable server side validation
myRequiredFieldValidator.Enabled = false;
//Disable client side validation
myRequiredFieldValidator.EnableClientScript = false;

But what if I want to enable the validator from javascript? I didn't find anything online about this so I debugged the ASP.NET js validation library to look for the method that enables the validation, and for the one that forces the validation check.

Enable a validator via javascript

The method to enable or disable a validator is:

function ValidatorEnable(val, enable)

where val is the reference to the <span> element that the validator uses to render the error message, and enable is a boolean to tell the method whether to enable or disable the validation.

Force a validation via javascript

In case you want to ask to a validator to do his job:

function ValidatorValidate(val, validationGroup, event)

val is again the reference to the validator <span>, validationGroup is the name of the validation group of the element that is triggering the validation, event is the reference to the event that triggered the validation. But only the first parameter is useful when you want to force the validation, since the others are used only by the standard validation of ASP.NET.

A real life example

Let's see a example from the code I'm writing for one of the new features of Subtext.
Imagine you have this snippet of HTML code:

<asp:DropDownList ID="ddlMimeType" runat="server">
   <asp:ListItem Value="mp3">audio/mpeg</asp:ListItem>
   <asp:ListItem Value="wma">audio/wma</asp:ListItem>
   <asp:ListItem Value="other">Other</asp:ListItem>
</asp:DropDownList>
<asp:TextBox id="txbOtherMimetype" runat="server" />
<asp:RequiredFieldValidator id="valOtherMimetypeRequired" runat="server"
                   ControlToValidate="txbOtherMimetype" ForeColor="#990066"
                   ErrorMessage="You have to specify a custom mimetype." />

And you want to enable the valOtherMimeTypeRequired validator only when the option selected in the drop down is "other".

Using jQuery here is the javascript code to do the job:

<script type="text/javascript">
$(document).ready(function()
{
  $("#<%= ddlMimeType.ClientID %>").change(function() 
  {
    toggleOtherMimeType(this);
  });
}

function toggleOtherMimeType(elem)
{
  if(elem!=undefined) 
  {
    if(elem.value=="other")
    {
      $("#<%= txbEnclosureOtherMimetype.ClientID %>").show();
      ValidatorEnable($("#<%= valEncOtherMimetypeRequired.ClientID %>")[0], true);
    }
    else
    {
      $("#<%= txbEnclosureOtherMimetype.ClientID %>").hide();
      ValidatorEnable($("#<%= valEncOtherMimetypeRequired.ClientID %>")[0], false);
    }
  }
}
</script>

Notice the <%= ddlMimeType.ClientID %> to select a server-side control using the automatically generated client ID and the $("#elemendId")[0] to get the real DOM element and not the jQuery wrapper around it.

And in case I wanted to force the validation I should have written:

ValidatorValidate($("#<%= valEncOtherMimeTypeRequired.ClientID %>")[0]);

It took me a while to find out this method name. I hope this will save you a bit of the time I spent hunting down the names using Firebug.

kick it on DotNetKicks.com

Technorati Tag: ,,
 

ASP.NET 3.5 + VS2008 SP1 beta

Probably you already read this announcement somewhere else in the net, so I'll not replicate the news here.

What excites me the most are mainly two things:

  • Part of the ASP.NET MVC framework are going to be included into the core ASP.NET framework: System.Web.Routing will be included in ASP.NET with the SP1, so around this summer, probably well before ASP.NET MVC is RTW
  • Intellisense will work for Javascript files, and will have support for jQuery, Prototype and other popular JS library out of the box.

You can read more about the other improvements on ScottGu blog and see what's really changing on ScottHa one.

Now off to downloading it, but going to run it only on a VM.


 

Problem with Spam? Waegis to the rescue

One of the problem of having a blog with a Google PageRank higher than 3 is that you get flooded by a storm of spam. Be it comment spam or trackback spam it's a waste of server resources and, if not filtered, could fill your blog with tons of sex related links and more.

Last year Subtext included a integration with Akismet, the de-facto only spam blocking service available for free on the net. But last autumn I received more than 1000 spam trackback in one day and more than 30.000 on the same day in my Italian blog and Akismet was not able to block them. So I was forced to disable them, and since then I don't trust Akismet any more.

Today Keyvan announced a project he has been working on in the last months (and thinking about for the last three years): Waegis.

Waegis is a online spam blocking service, but unlike Akismet it's build entirely with .NET, which helps .NET to gain a few points in the general web development community.

Aegis, in Greek mythology, was the shield of Zeus, the King of Greek Gods... let's see if it will defend us from the attach of the trackback spam.

Just a last note: today the Alpha release has been announced, so it will take a few months before it become available for the general public.

 

The most used Javascript Library is... jQuery

A month ago a popular CSS blog asked: "What is your Javascript library of choice?"

Yesterday, after having received more than 1600 answers, he published the results.

The winner is clearly jQuery, with more than 50% of the preferences (actually 52%).

The second library is MooTools with 15% and third comes Prototype with 12%.

As the author of the survey says, the audience of his website is mainly composed by designers, so the results are a bit biased toward jQuery (which has been designed to port the CSS way of thinking into JavaScript development).

But based on the previous JS library surveys I published on my blog I think that jQuery can be considered an overall winner:

  • in the survey about Ajax development in the .NET space, if we exclude the obvious winner which was ASP.NET Ajax, and the specific .NET frameworks, the first library was jQuery.
  • the generic Ajax development one (which has been answered mainly by PHP and Java developers), Prototype was the winner, but followed closely (only 5% less) by jQuery; and I guess that if that survey has been published now, due to the number of tutorial being published about jQuery, the results would have been reversed.
Technorati Tag: ,,,
 

Yet another Italian blogger starts blogging in English, on Subtext

Seems like a lot of Italian .NET blogger are making the big step of starting a blog in English: writing in a language that is not the one you use in your everyday life is not easy, but it can be a good way to improve the other language.

After 2 of the founders of UGIALT.net, Marco De Sanctis, a friend and active Italian community member started blogging in English on his brand new Subtext blog: CodeMetropolis.

Why an English blog? Well, honestly because I recently realized that I'm reading more English blogs than Italian ones, and that makes me feel as part of a .NET community that spans worldwide. I got so many visitors from abroad and I thought that the time has come for me to dive into a new challenging experience.

I'm going to talk about Software Design and Programming (which are both my everyday's bread and a great passion): some NHibernate, some WPF, some ASP.NET, some WCF and so on...! Let's see what happens!

You might already know Marco because he is the one that developed Blog Commander, a tool to bulk manage categories and tags of a blog.

So, let's welcome Marco and wish him good luck for this new experience.

Technorati Tag: ,,
 

The Panic Button

I use FeedDemon as my desktop newsreader and today, while looking around the UI I found a strange menu item: "Hit the Panic Button!".

menu_item

The button doesn't have the "..." that usually marks menu items that open a new dialog before doing something, so it frightened me a bit. But I finally decided to click on it and a dialog appeared:

panic_button

It's a really interesting feature: when you go on vacations and you come back and see 10k unread items, you just hit the Panic Button, and you are back to only one or two days of unread items. Cool, isn't it?

Technorati Tag: ,,
 

Second Italian ALT.NET conference

After the "small success" of the first UGIALT.net mini conference in February, UGIALT.net is organizing another conference in June.

The second UGIALT.net conference will take place on Saturday June 14th, and will take place at the offices of Avanade Italy, in the center of Milano.

As for the other conference there will not be a fixed agenda, but the event will be a day-long discussion on the topics decided by the participants, probably developing a small app to focus on the various stages of the development.

If you are Italian and want to know more about the event, please read my Italian blog: Seconda UGIALT.net conference - 14 Giugno 2008 - Milano

If someone outside Italy want to take part in the discussion the registrations are open on Facebook: http://www.facebook.com/event.php?eid=13361168300.

kick it on DotNetKicks.com

Technorati Tag: ,,
 

VMware Fusion 2.0: now with multiple displays

Since I installed Win2008 on my Mac I never really used it: turning on my company's laptop was less painful than the usability problems that both VMware and Parallels have.

VMware was not working very well with more than one display: if you open an application in Unity mode it will be stuck in the display the main Fusion application is running, and in fullscreen mode it is not possible to have more then one display.

Parallels works fine with multiple displays, but I don't like the way the mouse pointer is handled in Coherence mode: there are 2 pointers, with the one inside the Windows application that mimics the movements of the mac one.

But finally VMware Fusion 2.0 has been announced: with support for multiple displays, DirectX 9 3D support and more.

Watch the movie, with an astonishing 8 displays being supported!!

Now I think I can really start thinking of using my mac for everything, including developing on Visual Studio.

Technorati Tag: ,,