How to refer to a TextBox in JavaScript inside an ASP.NET control? -
i have asp.net control text fields , checkbox. modify checkbox state using javascript based on values present in text fields after page load.
how can reliably read text field values in javascript? saw this answer didn't help:
<asp:textbox text='<%# bind("something") %>' id="txtsomething" runat="server"> </asp:textbox> <script type="text/javascript"> alert($('#<%= txtsomething.clientid %>').val()); </script>
this doesn't work; vs tells me "txtsomething
not declared. may inaccessible due protection level."
how else can refer text box in javascript?
you can try client id of control contains text box , after search in children input id contains text box server id
<script type="text/javascript"> alert($('#<%= parentcontrol.clientid %>').find("input[id$='txtsomething']").val()); </script>
as option can do:
<script type="text/javascript"> alert($('#<%= (parentcontrol.findcontrol("txtsomething")).clientid %>').val()); </script>
Comments
Post a Comment