Hi,

I have a UserControl with two labels and a slider control on it. I have a javascript function that is called when the value of the slider changes, and it is supposed to update the text of the labels.

The ascx code is:
asp Code:
  1. <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="AlignSlider.ascx.vb" Inherits="F1TimeTrials.Controls.AlignSlider" %>
  2. <%@ Register assembly="Infragistics35.Web.v10.2, Version=10.2.20102.1011, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI.EditorControls" tagprefix="ig" %>
  3.  
  4. <script type="text/javascript" id="igClientScript">
  5. <!--
  6.  
  7.     function sliderControl_ValueChanged(sender, eventArgs) {
  8.         var leftLabel = document.getElementById('<%= Me.lblLeftValue.ClientID %>');
  9.         var rightLabel = document.getElementById('<%= Me.lblRightValue.ClientID %>');
  10.  
  11.         var maxValue = sender.get_maxValueAsDouble();
  12.         var value = eventArgs.get_newValue();
  13.         leftLabel.innerHTML = value;
  14.         rightLabel.innerHTML = maxValue - value;
  15.     }// -->
  16. </script>
  17.  
  18. <asp:Table ID="table" runat="server">
  19.     <asp:TableRow runat="server">
  20.  
  21.         <asp:TableCell runat="server">
  22.             <asp:Label runat="server" ID="lblLeftValue" Text="0" />
  23.         </asp:TableCell>
  24.  
  25.         <asp:TableCell runat="server">
  26.             <ig:WebSlider ID="sliderControl" runat="server" ValueType="Double" >
  27.                 <ClientEvents ValueChanged="sliderControl_ValueChanged" />
  28.             </ig:WebSlider>
  29.         </asp:TableCell>
  30.  
  31.         <asp:TableCell runat="server">
  32.             <asp:Label runat="server" ID="lblRightValue" Text="100"/>
  33.         </asp:TableCell>
  34.  
  35.     </asp:TableRow>
  36. </asp:Table>
When I put this control on a page it works just fine. I drag the slider, the labels update with the new values.


However, I actually need a large number of these controls on my page (around 10-20 I think), and this is where the problems start. When I change the slider on one of these UserControls, it changes the text of only the labels in the LAST instance of this UserControl on the page. It seems that the 'document.getElementById' function actually searches through the entire page rather than just the one UserControl.

How can I fix this? How can I get the two label controls from this current UserControl instance, and not any other instance on the page?