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

BSNL EVDO in Linux – The Easy Way

Posted on 17 Comments

BSNL EVDO
BSNL EVDO

So you just bought yourself a swanky new BSNL EV-DO broadband Internet device. It works happily on your Windows, fine, as they provide a Windows-friendly CD along with the device that installs the required software and drivers easily. But what about if you want to use your EV-DO in Linux, if you have it? Due to lack of official Linux support, setting up EV-DO in Linux can be quite tricky, but here is how to do it easily, without much fuss.

Linux comes in many flavors (from different vendors), like Ubuntu, openSuSE, Mandriva, Fedora, Mint. If you have one of these, or any modern Linux distro, proceed as follows.

In Linux, plug in the USB modem device. Now check if device nodes for it are created in your /dev folder. Usually, they are like /dev/ttyUSB0, /dev/ttyUSB1, /dev/usb/ttyUSB0, and so on. In most cases, this step should automatically happen. If it doesn’t, then you’ll have to manually create the device nodes for your USB modem by inserting its module in the kernel. To do it:

Check for the device ID of the USB modem. You do this using the following command. Run the command first with the modem unplugged, and then with modem plugged in. Compare the output in both the cases; whichever new entry appears in the list is of your modem.

lsusb

Within the output that you get, your modem (in most cases a ZTE device), will be listed something like:

Bus 002 Device 004: ID 19d2:fffe ZTE Corporation
or
Bus 002 Device 004: ID 19d2:fffe

Now using this device ID, you’ll create its device nodes by using this command:

depmod
modprobe usbserial vendor=0x19d2 product=0xfffe

This should create the relevant device nodes for the modem in /dev folder. If not, try unplugging and then plugging in the modem. Now your work is half done.

Next, you’ll need these packages installed to configure the modem:

wvdial
pppd
kppp or kinternet (for KDE users)
gnome-ppp (for GNOME users)

After making sure wvdial is installed, edit the file /etc/wvdial.conf to make it look similar to (note – you can use the command wvdialconf to setup the file automatically):

[Dialer Defaults]
Modem = /dev/ttyUSB0
Baud = 115200
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 =
Area Code =
Phone = #777
Username = xxxxxxxxxx
Password = xxxxxxxxxx
Ask Password = 0
Dial Command = ATDT
Stupid Mode = 1
Compuserve = 0
Force Address =
Idle Seconds = 0
DialMessage1 =
DialMessage2 =
ISDN = 0
Auto DNS = 1

Replace xxxxxxxxxx in case of username and password with the 10-digit phone number of your modem. Now, execute this command:

wvdial

Voila! Your Internet should work now, in full glory. To ease up things a bit, you may want to connect to Internet using a graphical (GUI ) tool everytime. Use kppp (KDE) or gnome-ppp (GNOME) for that.

UPDATE: As pointed out by my friend Yatin, NetworkManager is another great and easy way to setup EVDO. Most modern distros come pre-installed with it. If not, you can always install it manually.

Updating Fedora

Posted on 4 Comments

I’ve never really updated an entire OS in the strictest sense. When I say I have an up-to-date OS, that means I’ve all the major applications (mostly UI-based) in their latest versions. But this time I decided, having gotten back by beloved EV-DO, to go for a full OS update for my Fedora 11 (Leonidas). The command was as simple as:

yum update –skip-broken

Issuing the command showed there were approx. 1 GB worth of updates to be installed. But why think twice about the download size when you have an EV-DO with an unlimited data plan? Also, that gave me a reason to keep the EV-DO busy. I love downloading. I simple love it!

I’ll post some screenies of my updated Fedora as soon as it gets updated fully.

Update: Here is a screenshot of my updated desktop. Pretty, isn’t it? And reminiscent of my XP desktop a while back.

My updated Fedora 11
My updated Fedora 11

Tutorial: AJAX with jQuery

Posted on 1 Comment

jQuery is a very powerful JavaScript framework, and to put in their own terms, is The Write Less, Do More JavaScript library. jQuery’s slogan indeed holds true to its claim, as you’ll discover as soon as you start coding using jQuery. Although jQuery has an extensive set of API and a collection of many functions in its arsenal, I would be concentrating more on the AJAX capabilities of jQuery in this tutorial.

Most of the modern websites, irrespective of whether they offer a simple or a complex interface, usually use AJAX for some task or the other. While designing in order to cater to today’s needs, it becomes almost indispensable to use AJAX to make the end-user experience faster and more pleasant. So, if you had been deferring the use of AJAX till now owing to it’s complexity in raw JavaScript, here is your chance to start using it with utmost ease.

It is really amazing to see how much simplified AJAX is with jQuery. The developers have seemingly (and painstakingly) done a lot of hard work behind the scenes to make it easy for the web developer to implement even the most complex JavaScript concepts, including AJAX.

For the purpose of demostrating AJAX, I’ll be making use of a simple web application (that I designed using HTML, PHP, jQuery, CSS and MySQL). I call it the Albums Database.

Continue reading Tutorial: AJAX with jQuery