tags:

views:

51

answers:

3

Hi i have a radiobutton list and on click on the radio button item i have to change text of a label. But for some reason its not working. Code is below

<asp:Label ID="lblVessel" Text="Vessel:" runat="server" ></asp:Label>


<script language="javascript">

    $(document).ready(function() {

       $('#rblDiv input').click(function()
       {
            var selected= $("#rblDiv input:radio:checked").val();
            if(selected == "exportpack") 
            {
              $('#lblVessel').text("NewText");
            }
       });
});

</script>

Please Advise

+5  A: 

ASP.Net automatically generates unique client IDs for server-side controls.

Change it to

 $('#<%= lblVessel.ClientID %>')

In ASP.Net 4.0, you could also set the ClientIDMode property to Static instead.

SLaks
thanks that worked
Amit
+1  A: 

I'm not an ASP.NET guy but I think the id generated for the browser doesn't retain the ID you provided for it on server side.

Do a view source and paste the relevant code here.

Allain Lalonde
A: 

Try this:

$('[id$=lblVessel]').text("NewText");

The id$= will match the elements that end with that text, which is how ASP.NET auto-generates IDs. You can make it safer using span[id=$=lblVessel] but usually this isn't necessary.

Codesleuth