Set label when changing slider value - nested control

4 posts, 0 answers
  1. Mateusz
    Mateusz avatar
    14 posts
    Member since:
    Aug 2012

    Posted 13 Sep 2012 Link to this post

    Hi, i have a radslider and a label nested like this:

    <telerik:RadTreeList>

     <EditFormSettings EditFormType="Template">

      <FormTemplate>

        <asp:Panel>

            <asp:Label />

            <telerik:RadSlider />

    .....

    I try differnet approches to set the label text to choosen radslider value. But i cant seem to find the controls.

             

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Sep 2012 Link to this post

    Hi Mateusz,

    I suppose you want to access the Label and RadSlider which is inside the FormTemplate. Following is the sample code.

    ASPX:
    <EditFormSettings EditFormType="Template">
        <FormTemplate>
             <asp:Label ID="Label1" runat="server" Text="Label1"></asp:Label>
             <telerik:RadSlider ID="RadSlider1" runat="server"></telerik:RadSlider>
        </FormTemplate>
    </EditFormSettings>

    C#:
    protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
        {
            if (e.Item is TreeListEditFormItem && (e.Item as TreeListEditFormItem).IsInEditMode)
            {
                TreeListEditFormItem editFormItem = e.Item as TreeListEditFormItem;
                TreeListDataItem parentItem = editFormItem.ParentItem;
                Label Label1 = editFormItem.FindControl("Label1") as Label;
                RadSlider RadSlider1 = editFormItem.FindControl("RadSlider1") as RadSlider;
            }
        }

    Hope this helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mateusz
    Mateusz avatar
    14 posts
    Member since:
    Aug 2012

    Posted 13 Sep 2012 Link to this post

    sorry. I forgot to mention that i want to display the value in js without involving server side...
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Sep 2012 Link to this post

    Hi,

    One suggestion is that you can access the label from server side and pass the ClientId of the label as shown below.
    aspx:
    <EditFormSettings EditFormType="Template">
        <FormTemplate>
             <asp:Label ID="Label1" runat="server" Text="Label1"></asp:Label>
             <telerik:RadSlider ID="RadSlider1" OnClientValueChanged="OnClientValueChanged" runat="server"></telerik:RadSlider>
        </FormTemplate>
    </EditFormSettings>
    C#:
    protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
     {
       if (e.Item is TreeListEditFormItem && (e.Item as TreeListEditFormItem).IsInEditMode)
       {
        TreeListEditFormItem editFormItem = e.Item as TreeListEditFormItem;
        Label Label1 = editFormItem.FindControl("Label1") as Label;
        RadTreeList1.Controls.Add(new LiteralControl("<script type='text/javascript'>window['lbl'] = '" + Label1.ClientID + "';</script>"));
         }
    }
    JS:
    <script type="text/javascript">
      function OnClientValueChanged(sender,args)
     {
      var lbl = document.getElementById(window['lbl']);
      lbl.innerHTML = sender.get_value();
     }
    </script>

    Thanks,
    Princy.
Back to Top