Skip to main content

Posts

Showing posts from 2010

Why Why there is no Trim function on JS

It was pretty bad when you find that the JS dos not have a inbuilt function on strings to do Trim. But not to worry. It can be implemented easily. function LTrim(str){ var whitespace = new String(" \t\n\r"); var s = new String(str); if (whitespace.indexOf(s.charAt(0)) != -1) { var j=0, i = s.length; while (j < i && whitespace.indexOf(s.charAt(j)) != -1) j++; s = s.substring(j, i); } return s; } function RTrim(str){ var whitespace = new String(" \t\n\r"); var s = new String(str); if (whitespace.indexOf(s.charAt(s.length-1)) != -1) { var i = s.length - 1; while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--; s = s.substring(0, i+1); } return s; } function Trim(str){ return RTrim(LTrim(str)); }

Download file by IE error with SSL

It took a long time to figure out what was going wrong since on all the other browsers the file was able to download but IE (6,7 & 8) . Tried a lot of things which the forums said but at last at last found the solution. Microsoft agrees this as an issue of IE and they have given the patch here.  http://support.microsoft.com/kb/323308 And also if a header was added as  "CACHE-CONTROL":"NO-CACHE" it will not work on IE even with the fix MS given. It should be changed as "Cache-control:no-store". 

JQuery API control functions

Image from hoth.entp.com I was doing JavaScript for few years and it was little bit hard to work with "write less, do more" at first few times. Always it comes to my mind as JavaScript (yes I know it is) so I am trying to apply some functions as document.getElementById. And when I wanted to hide and show elements it was style:none and block.Those look bad(when a better way is there) on jQuery and some of them may not work on jQuery elements. OK I am not here to teach you neither JavaScript nor jQuery. For the people like me it is strongly recommended (by me of course) to take a look at the available and right functions on jQuery API official site .t I just found that and thought to share that. If you got a better place or some useful links please share it.

A JavaScript Alert as I want

There are alerts and confirms on JS as you all know. But its look and feel is same old style. I was curious whether we can change it. Of cause we are normally using a div tag and apply some styles to the background to gray out. Then we can use it as a function and call it whenever we need an alert. Isn’t there a better way to do that? I mean much easier way. So what I have tried to do was override the alert functionality on JS and give a customized method to do the job. So then what happens is we don’t need to change the code on each and every place where it used alert(“this is message”); . I have found the way to this on http://slayeroffice.com/code/custom_alert/ This place can be changed so I have pasted the JS code also in here. // constants to define the title of the alert and button text. var ALERT_TITLE = "Oops!"; var ALERT_BUTTON_TEXT = "Ok"; // over-ride the alert method only if this a newer browser. // Older browser will see standard alerts if(docume...

How to call a web method by JavaScript

I didn’t get a time to write something here for a long time. Yes I can say I was busy. (But I was not :)) Anyway I thought to write about something finally and I promise (this is a serious promise) that I will try to do something (do a posting actually) on my blog more frequently. The ability to call the web methods by JavaScript on .net is very very useful and we can implement the web pages more efficiently by using this. For example we do not need to send whole page and update. Yes this is AJAX (that what I think). Here is a web method example. It should be on the aspx page code behind and should be a static (shared) method. I have tried to insert the web methods on user controls and was unable to do so (if you know a way please share with us). This is on VB.net. _ Public Shared Function GetMyData(ByVal studentID As Integer, ByVal schoolID As Integer) As Student Dim studentService As New StudentService() Dim result As Student = studentService.GetStudent(studentI...