Search code examples
javascriptasp.netclient-sideascx

SYNTAX HELP: How to Find control in javascript ?


I am trying to implement server side code on client side. "trvddl1" is a ascx control which contains a dropdownlist "ddltree". It was easy on server side but I am facing difficulty using the same in javascript.

How do I write the following code in javascript?

((DropDownList)trvddl1.FindControl("ddltree")).SelectedValue;

I tried

var abc = document.getElementById('<%=trvddl1.ClientID%>').value;

and

var Region = document.getElementById('<%=trvddl1.FindControl("ddltree")%>').value;

but javascript returned error. Is there some other keyword I am missing ?


Solution

  • Check the HTML output (Browser-->View Source) and locate the control there, see what the ID of that control has, and put that one into the getElementById() function.

    Example:

    <input id='ddltree' .... />
    

    Then use:

    var abc = document.getElementById('ddltree').value;