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

Triggering events of series of dynamic sliders

2 Answers 24 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 06 Aug 2010, 08:22 PM
Hi, I am using a database query to setup a series of dynamic sliders within a panel.  In the PreRender, the following code successfully generates the sliders:

For Each LocRec In LocRecs
    Dim LocationSlider As New RadSlider()
    Dim LocationLabel As New Literal
    LocationLabel.Text = "<br />" & LocRec.LocationName & "<br />"
    LocationSlider.ID = "LocationSlider" & CStr(LocRec.LocationID)
    LocationSlider.Width = 300
    LocationSlider.AutoPostBack = True
    LocationSlider.MinimumValue = 0
    LocationSlider.MaximumValue = 1000
    LocationSlider.OnClientSlide = "OnClientSlide"
    LocationSlider.OnClientValueChanging = "OnClientValueChanging"
    LocationSlider.AnimationDuration = 400
    AddHandler LocationSlider.ValueChanged, AddressOf LocationSlider_ValueChanged
    Panel1.Controls.Add(LocationLabel)
    Panel1.Controls.Add(LocationSlider)
Next

The problem is that the event, LocationSlider_ValueChanged never gets triggered:

Public Sub LocationSlider_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    'Write slider settings to the database
    'This routine never gets executed
End Sub

Why?  How can I capture the valuechanged event?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 12 Aug 2010, 12:27 PM
Hi Paul,
You add the slider control to the Controls collection of the page too late in the page lifecycle for the event to fire. You can test this with a standard ASP Button control:
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
    Dim button As New Button
    button.ID = "Button1"
    AddHandler button.Click, AddressOf Button1_Click
    Page.Form.Controls.Add(button)
End Sub

I would recommend that you move the code that creates the slider control to Page_Init. You can read more about Control Execution Lifecycle in MSDN - http://msdn.microsoft.com/en-us/library/aa719775%28VS.71%29.aspx.

All the best,
Tsvetie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Paul
Top achievements
Rank 1
answered on 22 Aug 2010, 11:14 PM
Thanks Tsvetie.  That did it!

Best,

Paul.
Tags
Slider
Asked by
Paul
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Paul
Top achievements
Rank 1
Share this question
or