Monday, April 2, 2012

ASP.NET AJAX not working on Google Chrome and Safari - Update panel/Popup Extender.

Recently i faced this issue when working with ASP.NET Ajax Updatepanel and Popup extender. The Popup was always visible and took a fixed space on the page like a normal div.

Added the below javascript code to a .js file.
Sys.Browser.WebKit = {}; //Safari 3 is considered WebKit
if( navigator.userAgent.indexOf( 'WebKit/' ) > -1 )
  Sys.Browser.agent = Sys.Browser.WebKit;
  Sys.Browser.version = parseFloat( navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]); = 'WebKit';

Refer the .js file in the ScriptManager.
<ajax:ToolkitScriptManager ID="scripts" runat="server" ScriptMode="Release" EnableHistory="true"
EnableSecureHistoryState="false" EnablePageMethods="True" CombineScripts="true"
OnAsyncPostBackError="Page_OnAsyncError" OnNavigate="OnHistoryNavigate">
        <asp:ScriptReference Path="~/js/webkit.js" />

Sunday, April 1, 2012

JAVASCRIPT - How to remove last character from string

A common requirement, I have been approached is to have a javascript function to remove last character of a string. This is usually for some delimited string like a comma separated string.

var yourStr = "1, 2, 3, 4,"    
var yourstrLen =  yourStr.length;
yourStr =  yourStr.slice(0,yourstrLen-1);
alert (yourStr);

Instead of 
    yourStr.slice(0, 1); is also equally acceptable, because negative value sets offset from the end of the string.