Monday, September 19, 2011

Multilingual website in asp.net

While its neither new nor overly complex to implement multiple languages in ASP.net, it can be at times confusing and at times bit over the top in certain scenarios. ASP.net provides resource files which can be used to update the content based on browser language choice. The other option is to have a button or user choice saved in the database which is picked up as soon as user logs in. 

Before moving further let me explain a bit what need to done at the html level, first this is key as if you have not planned for this from the start doing this at the last step can get very irritating, while defining the labels/ literals that need to switched over to the other language in addition to ID and Runat tag you need to define resource key like meta:resourceKey ="FirstName" the same needs to be define in the corresponding resource file. with this out of the way, we need to set the page UICulture and Culture the same can be set at Page directive level and in web.config level if you want it to static at global level in the application. 

now we need to override the page Initialize Culture method as shown below, here we are fetching user selected language from class user as a property. and rest is just setting of values no rocket science here.

protected override void InitializeCulture()

 {

        clsUsers obj = new cls.Users();
                                String selectedLanguage = obj.Language;

        UICulture = selectedLanguage;

        Culture = selectedLanguage;

        Thread.CurrentThread.CurrentCulture =
                CultureInfo.CreateSpecificCulture(selectedLanguage);
       Thread.CurrentThread.CurrentUICulture = new
       CultureInfo(selectedLanguage);
      base.InitializeCulture()

}

an alternative to doing this at every page is using a base page class, here a class is inherited by System.Web.UI.Page and above method is written once and same is applicable in all the pages that inherit from base page instead of System.Web.UI.Page. More on base page is updated on the blog.

This is how the class will look like 
public class BasePage : System.Web.UI.Page

This how pages.cs will look like
public partial class UserInfo : SomeProject_BLL.BasePage

Looking forward to your comments 


Hold Up

Tuesday, September 6, 2011

Jquery Graphs

Recently I had to come up with a low cost graphing solution for one of my clients, little did I know that Jquery Graphs would not only be a fringe tools, but something that can be used professionally as well. That said there are both paid and free tools which meet professional standards and are as good as it gets features available. some of the key pro and cons of using jquery graphs are listed below 

PROs
  1. Light weight and very small foot print 
  2. Client side control, so resources are not consumed on the server, and jquery calls can be made to get real time data or read of a XML
  3. Interactive UI, clicks on graphs and specific bars or section can be handled in most tools available.
  4. Easy to implement
  5. Most Important fact is that most of these are actually HTML 5 compliant and render well on all modern browsers


CONs
  1. Lacks support in older browsers support, though they us excanvas.js it fails at times
  2. If you opt for a free tool, you may struggle to find support on the tool
  3. can be complex to use with AJAX or other scripting libraries.
Some of the tools i reviewed are listed below in particular order

  1. JQPlot - Free but an advanced library 
  2. HighCharts - Paid but really good.... you pay $80 for a single site without any login or user based data, but if you have a login and user based data then the price moves to $360.
  3. Flot - Good but the library lacks good examples and documentation and is sightly harder to work on. 




Hold Up