Thursday, October 20, 2011

calling Javascript methods on updatepanel events

Recently came up with a scenario where I need to call a Javascript function to update a label with client side time on auto save, while auto saving was working fine, the only issue was capturing the time, since the label was updated at server we would end up with server time, so the do get client side time the option is to call a JS function at end request of update panel now the problem, there are multiple update panels on the page how do we know which panel is called, after digging a lot, I fond this discussion on stack overflow http://stackoverflow.com/questions/338702/how-to-call-a-client-side-javascript-function-after-a-specific-updatepanel-has-b 


Code on stack overflow


$(document).ready(function() {
 panelsLoaded = 1;   Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoaded) 
 }); 


 function PageLoaded(sender, args) { 
   console.log("I have occured " + panelsLoaded++ + " times!"); 
   var panelsCreated = args.get_panelsCreated(); 


   for (var i = 0; i < panelsCreated.length; i++) { 
     console.log("Panels Updating: " + panelsCreated[i].id); 
   } 
  var panelsUpdated = args.get_panelsUpdated(); 


 for (var i = 0; i < panelsUpdated.length; i++) { 
 console.log("Panels Updating: " + panelsUpdated[i].id); 
 } 
 } 


My Modified version 


$(document).ready(function () {        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoaded) 
 }); 


function PageLoaded(sender, args) { 
  var panelsUpdated = args.get_panelsUpdated(); 


  for (var i = 0; i < panelsUpdated.length; i++) { 
     if(panelsUpdated[i].id == "<%=UpdatePanel2.ClientID%>") { 
                 alert('timer called');                     
         } 
     } 
 } 


This enabled us to call timer string update after isolating the update panel, we thanks james for sharing this code, in the first place. Hope this is useful to you, please give your comments and share this article if you do.




Hold Up


kick it on DotNetKicks.com

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

Tuesday, May 17, 2011

NopCommerce - Opensource and effective

This would be the first off the shelf product i am promoting, but i just cant help it, the cart is so dam good, you think that there has to be catch to it but there is none. I have been reviewing this for a while and now i am implementing it for one of my clients. I find it to be very flexible and the forum is great it help out on almost anything. The code is very well structured and does take some getting used to but in the end, it follows all the good practices and have a flexibility of any paid shopping carts. It comes highly recommended from Micosoft as well. 


It is expected that there will be a MVC 3 version out somtime in july


nopCommerce offers unprecedented flexibility and control. Since it is open-source, nopCommerce’s source code is available free for download. Just click here to download your copy today.