Reputation: 109
How to get the id of control which is created at run time in asp.net. I want to get that Id in javascript.
the actual id which I am setting is ctus_txtFirstName
at run-time the id is MainContent_ctus_txtfirstName
Upvotes: 1
Views: 2921
Reputation: 35407
Use the server control's ClientID
property. It'll output the correct ID, containing the fully qualified Naming Container.
<script>
var ctrl = document.getElementById('<%= txtFirstName.ClientID %>');
console.log(ctrl.value);
<script>
This is only applicable if you're using server controls. Plain markup will not have a Naming Container, if the runat="server"
attribute is omitted.
Upvotes: 3