I have a radiobutton list and on click on the radio button item I have to change the text of its label. But for some reason it’s not working. Code is below:
JavaScript
x
14
14
1
<asp:Label ID="lblVessel" Text="Vessel:" runat="server"></asp:Label>
2
3
<script language="javascript">
4
$(document).ready(function() {
5
6
$('#rblDiv input').click(function() {
7
var selected = $("#rblDiv input:radio:checked").val();
8
if (selected == "exportpack") {
9
$('#lblVessel').text("NewText");
10
}
11
});
12
});
13
</script>
14
Advertisement
Answer
ASP.Net automatically generates unique client IDs for server-side controls.
Change it to
JavaScript
1
2
1
$('#<%= lblVessel.ClientID %>')
2
In ASP.Net 4.0, you could also set the ClientIDMode
property to Static
instead.