This is a migrated thread and some comments may be shown as answers.

Set label when changing slider value - nested control

3 Answers 145 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Mateusz
Top achievements
Rank 1
Mateusz asked on 13 Sep 2012, 10:28 AM

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.

         

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Sep 2012, 12:31 PM
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.
0
Mateusz
Top achievements
Rank 1
answered on 13 Sep 2012, 12:39 PM
sorry. I forgot to mention that i want to display the value in js without involving server side...
0
Princy
Top achievements
Rank 2
answered on 14 Sep 2012, 05:32 AM
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.
Tags
Slider
Asked by
Mateusz
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mateusz
Top achievements
Rank 1
Share this question
or