Posted on 2 Comments

How you determine your age?
I was born in 1987 and this is 2011, so I am 24 years old right now.

How most computer systems determine your age?
Time passed since 1st January 1970 till now (2011)
Time passed since 1st January 1970 till when you were born (1987)
(well, again) 24

The date 1st January 1970 is the Epoch date for the computer, signifying the start of time for it. That’s why timestamps in most programming languages are the seconds/milliseconds elapsed since the epoch.

Accessing ASP.NET Controls in JavaScript Code

Posted on 1 Comment

ASP.NET controls essentially translate to a bunch of HTML and JavaScript code when being rendered in the browser, because HTML and JS is all what a browser can understand. So does that mean you can access an ASP.NET control with ease through JavaScript? Yes and no. Really depends on the version of .NET installed on the server (hosting your ASP.NET website).

HTML controls/elements/tags are generally referred to by their IDs. In plain JS, we would do something like:

var name = document.getElementById('txtName').value;

In jQuery, that would translate to:

var name = $('#txtName').val();

That’s assuming that your page has a text box with the ID ‘txtName’. One would expect that ASP.NET controls can also be referred to by their IDs in JavaScript. But that’s not always true. Prior to .NET 3, a compiler-generated prefix used to get added to a control’s ID (while rendering it in browser), to form what’s called the control’s ClientID. An example of such a ClientID can be “ctl00$mainpage$txtName”. In short, if you have an ASP.NET 3.0 textbox control having an ID ‘txtName’, you can access it in JavaScript like:

var name = document.getElementById('txtName').value;

But obviously, that won’t work in case of ASP.NET 2.0, because the actually ID you want to refer to is “ctl00$mainpage$txtName”.

That is where the ASP.NET short tag notation comes into play. Regardless of whatever version of .NET is installed on your server, you can access an ASP.NET control in JS in the following way:

var name = document.getElementById('<%= txtName.ClientId %>').value;

Of course, you can directly do something like:

var name = <%= txtName.Text %>;

Well, all depends on your needs. This tip is just meant to get you started with the interoperability between ASP.NET and JavaScript. And remember, the ASP.NET short tag notation works the same way in case of HTML too.

Further Reading
You can even have ASP.NET methods return data to your JavaScript code. That can be done with a little-bit of AJAX and by declaring your ASP.NET methods as webmethods. This beautiful tutorial discusses how to do just that (in plain JS and in jQuery)

Fixing iPod’s messed up album art issue

Posted on 2 Comments

Accessing the songs in your iPhone or iPod Touch through an application other than iTunes might get the album (cover) art of some or all of your songs completely messed up. Messed up as in missing or mismatched album arts. This happened to me when I played certain iPod songs in Banshee and Rhythmbox (music players for Linux). If you’ve gotten in a similam situation, here’s what to do to fix it.

The trick is to play each and every song in your collection in iTunes (with a bad album art) for a few seconds. Yes, it may turn out to be a time-consuming and lengthy process, but the only way to fix the issue. If you have a super-huge collection of songs, then God save you. 😉

Posted from Apple Computers Ipod Touch

Excited to play Portal 2

Posted on 2 Comments

Wow! I got my Portal 2 the next day of ordering it from an Indian online games store (nextworld.in). That was impressive!

Immediately after finishing Portal (the prequel), I wanted to play the sequel (ah yes, I knew at the time that a sequel was in the pipeline). Portal was damn good: a fun way of solving puzzles the FPS way. Now to get my hands on the live gameplay when I get the time to install it. 🙂

Google network’s performance on BSNL EVDO in Linux

Posted on 1 Comment

has been annoyingly sluggish ever since. Pinging Google sites via command-line shows heavy packet losses. I use the same browsers in Linux (Chrome & Firefox), and the same browsers in Windows. Still, performance of all Google (and related) sites is very poor in Linux (but OK in case of Windows) due to an arcane reason that is still now clear to me. Even (innocuously) normal sites with Google ads take 4-5 refreshes to load properly. And don’t forget almost no site (ok, except some only-HTML stone-age sites still lurking around) in the world today are devoid of those nasty Google ads.

So until I solve the mystery, Google will keep me frustrated in Linux.