Thomas’ Developer Blog

October 12, 2008

Quick tip on client side IDs in custom controls for javascript use.

Filed under: Asp.Net Framework 2.0, Custom Controls, javascript — Tags: , , , , , , , — sanzon @ 7:23 pm

Well one thing I found annoying when developing custom controls that use javascript is what do you do when you need to give an ID to a html dom object within a custom control in order to use it with javascript!

I thought at first, ok I could do some complex child/parent relationship coding, which I try not to do a ton of, but it works really well at times. In this case it would be too much of a pain. So I came up with another solution to this little problem and it’s not hard when you think about it.

ClientID’s often look like ct100_SomeID_SomeChildID_ETC

Well if you think about valid ID names, ID’s cannot start with a number! So the answer is pretty simple when you think about it.

Simply take the base ID of ct100_SomeID and attach a string such as, “_100jso_myID”

It produces something like:

The great part about using a numeric value first is that it’s impossible to use a child control named 100jso, so it passes just fine. In case you’re wondering jso stands for javascript object in this case. I guess hdo, or html dom object may make more sense. Long as it starts with a number it’s safe!

So when you do work with javascript simple call:

document.getElementById(‘” & myBase.clientID & “_101jso_ClientID”‘)

Hope this helps


1 Comment »

  1. Do you mind if I quote a few of your articles as long as I
    provide credit and sources back to your webpage? My blog site
    is in the very same area of interest as yours and my visitors would certainly benefit from some of the information you
    provide here. Please let me know if this ok with you.
    Thank you!

    Comment by designer kids clothes — July 30, 2013 @ 4:36 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: