We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Unable to FindControl and Modify Value at Runtime


I'm using vb.net: I have a sub (BuildMyGauge) in code behind that dynamically creates circular gauges depending on rows from DataTable [If datatable returns 3 rows the Sub will build 3 Circular Gauges].  The gauge properties and an initial Pointer Value is also set in this sub (BuildMyGauge).  At Runtime, each circular gauge is given a unique ID, I also use a timer to continuously update the Pointer Value.

I use the findControl method in the timer event to find the Gauge Controls and update the pointer values.  The timer event and code in the timer event runs....but it does not update the controls on the asp page.

For now i just want to update the first control that is created and its ID is always CircularGauge0

Partial Class live_mote
    Inherits System.Web.UI.Page
    Private LiveMoteGaugeArray As New CircularGauge()
    Private msqlDataTable As New DataTable
    Private intControlNumber As Integer

    Private Sub BuildMyCircularGauge()

       msqlDataTable = generalDAL.GetSensorConfiguration

        '    'This sets up each gauge for each registered sensor on the mote
        For Each Row As DataRow In msqlDataTable.Rows

            With LiveMoteGaugeArray
                .AutoFormat = GaugeSkins.Midnight
                .ID = "CircularGauge" + Convert.ToString(intControlNumber)
                ' .Radius = 70
                ' .Height = Unit.Pixel(200)
                ' .Width = Unit.Pixel(200)
            End With

            Dim GaugeScale As New CircularScale()
            With GaugeScale
                .Minimum = 0
                .Maximum = 100
                .StartAngle = 115
                .SweepAngle = 315
                .MinorIntervalValue = 5
                .ScaleBarSize = 10
                .ScaleDirection = ScaleDirection.Clockwise
            End With

            Dim GaugePointer1 As New CircularPointer()
            With GaugePointer1
                .BackNeedleLength = 10
                .NeedleStyle = NeedleStyle.Triangle
                .PointerNeedleType = PointerNeedleType.Needle
                .PointerPlacement = ScalePlacement.Near

                'This gets the latest value from the database table and sets value on the gauge
                If Convert.ToInt16(msqlDataTable.Rows(intControlNumber).Item(0).ToString) = 2 Then
                    .Value = realtimeDAL
                ElseIf Convert.ToInt16(msqlDataTable.Rows(intControlNumber).Item(0).ToString) = 3 Then
                    .Value = realtimeDAL
                ElseIf Convert.ToInt16(msqlDataTable.Rows(intControlNumber).Item(0).ToString) = 4 Then
                    .Value = realtimeDAL

                End If

            End With

            Dim GaugeTick1 As New CircularGaugeTick()
            With GaugeTick1
                .TickStyle = TickStyle.MajorInterval
                .TickHeight = 10
            End With

            Dim GaugeTick2 As New CircularGaugeTick()
            With GaugeTick2
                .TickStyle = TickStyle.MinorInterval
                .TickHeight = 5
            End With

            Dim GaugeLabel1 As New CircularGaugeLabel()
            With GaugeLabel1
                .LabelStyle = TickStyle.MajorInterval
                .LabelPlacement = ScalePlacement.Near
                .Font = New Syncfusion.Web.UI.WebControls.Gauge.Font("Arial", "12", FontStyle.Bold)
            End With

            Dim GaugeLabel2 As New CircularGaugeLabel()
            With GaugeLabel2
                .LabelStyle = TickStyle.MinorInterval
                .LabelPlacement = ScalePlacement.Near
                .Font = New Syncfusion.Web.UI.WebControls.Gauge.Font("Arial", "12", FontStyle.Bold)
            End With

            intControlNumber = intControlNumber + 1

    End Sub
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load


    End Sub
    Protected Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim xxx As CircularGauge
        xxx = Page.FindControl("CircularGauge0")
        xxx.Scales(0).Pointers(0).Value = Convert.ToDouble("10")

    End Sub
End Class

1 Reply

AT Anandaraj T Syncfusion Team September 4, 2015 12:09 PM UTC

Hi Rakesh,

Thanks for using Syncfusion products.

We have analyzed the code snippet provided by you and found that static value (10) is used for updating the pointer value. Since there is no change in circular gauge, same circular gauge will render during timer ticks. If we use a random value to update the pointer, we can see the changes in circular gauge.

Please refer the following code snippet to achieve this

    Protected Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        Dim gauge As CircularGauge

        Dim r As New Random

        For i As Integer = 0 To intControlNumber - 1

            gauge = Page.FindControl("CircularGauge" + i.ToString())

            gauge.Scales(0).Pointers(0).Value = r.Next(gauge.Scales(0).Minimum, gauge.Scales(0).Maximum)

    End Sub

We have also created a simple sample based on your code snippet and it can be downloaded from the following link

Please let us know if you have any concern.


Live Chat Icon For mobile
Up arrow icon