February 2012 Entries

How to truncate string without breaking a word in half
Sometimes you need to shorten a long string to certain length without cutting the final word in half and add custom string such as 3 dots to the end, It will moves the pointer up to the previous space, if the limit finished within a word. Here I listed 3 functions may help you. Javascript function Truncate(str, maxLength, suffix) { if(str.length > maxLength) { str = str.substring(0, maxLength + 1); str = str.substring(0, Math.min(str.length, str.lastIndexOf(" "))); str = str + suffix; } return ......

Posted On Sunday, February 19, 2012 1:32 PM | Comments (2)

Use window.onbeforeunload event to stop browser from closing or Disable Button before Page PostBack
All modern browsers support the JavaScript's window.onbeforeunload event. It fires before the unload event when the page is unloaded. So this event always uses to stop a page from exit. The following codes illustrate how to implement this function: window.onbeforeunload = function (e) { var message = 'Are you sure you want to leave?'; var e = e || window.event; // For IE and Firefox prior to version 4 if (e) { e.returnValue = message ; } // For Safari return message; }; and we can also use this event ......

Posted On Wednesday, February 15, 2012 9:51 PM | Comments (5)

How to check/uncheck all checkbox with Jquery
There are a lot of solutions for this, but I found most them did not handle the case where user checked or unchecked all of the child checkboxes and it must automatically checked or unchecked the parent checkbox. so I give the following solution: <html xmlns="http://www.w3.org/19... <head runat="server"> <title></title> <script src="Scripts/jquery-1.4.1.m... type="text/javascript">&... <style type="text/css"> .cbRowItem {display:block;} </style> ......

Posted On Wednesday, February 15, 2012 2:04 PM | Comments (0)

Easy way to force designer.cs to update
We always have a problem that Designer.cs not updating automatically when we add new controls in markup or the designer, and if we want to get it in code behind, it doesn’t show up. I have met this problem when I add a usercontrol in aspx file. So I change source view to design view and switch back and forth, even I reopen my solution and rebuild, it still cannot be found. At last, I find a easy way to solve it : 1. Close designer.cs. 2. Change your aspx file to design view. 3. Right-Click –> ......

Posted On Wednesday, February 15, 2012 2:55 AM | Comments (3)

Add SM (Service Mark) symbol for radeditor

Use blow javascript to add a command for radeditor

RadEditorCommandList["InsertSM"] = function (commandName, editor, oTool) { 
        editor.PasteHtml('<sup>SM</sup>'); 
    };

Posted On Tuesday, February 14, 2012 7:54 PM | Comments (0)