Triggering events of series of dynamic sliders

3 posts, 0 answers
  1. Paul
    Paul avatar
    5 posts
    Member since:
    Jul 2010

    Posted 06 Aug 2010 Link to this post

    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. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 12 Aug 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul
    Paul avatar
    5 posts
    Member since:
    Jul 2010

    Posted 22 Aug 2010 Link to this post

    Thanks Tsvetie.  That did it!

    Best,

    Paul.
Back to Top