views:

50

answers:

3

How to find the control type in javasccript?. Say if i have an ASP.NET LinkButton and i wanna find control type from the javascript. How can i do that. I tried using typeof(), but it giving me an object back. and i tried

var control = document.getElementById(Id);//Id is the ClientId of the Linkbutton
alert(control.type);//this is empty.
A: 

LinkButton is a server side type of control, but in the client side (javascript) there is not a LinkButton but the HTML tags rendered by that control which probably include tags.

So, in the javascript it makes not sense to talk about LinkButtons.

Probably there is a better solution for what you are trying to accomplish.

gustavogb
yeah.. anyways it will render as anchor tag. How to know that it is an anchor tag?
Nimesh
control.tagName == 'a'
gustavogb
+3  A: 

Hi,

You can't find the controltype as in ASP.NET in javascript I think. There is the attribute tagName that may help you:

control.tagName returns the HTML tagname. If you really want the ASP control name, you can try to put the controlname in for example the class attribute.

VeeWee
You're right. Demo [here](http://jsfiddle.net/32s5u/).
sje397
+2  A: 

you can't get control type directly by javascript. you can try to use some serverside code to determine control class name:

var cType = '<%= Type.GetType(yourControlServerName).ToString() %>';
alert(cType);
Pavel Morshenyuk