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.
Unfortunately, activation email could not send to your email. Please try again.

Unable to FindControl and Modify Value at Runtime

Thread ID:

Created:

Updated:

Platform:

Replies:

120122 Sep 2,2015 04:51 AM Sep 4,2015 08:09 AM ASP.NET Web Forms (Classic) 1
loading
Tags: CircularGauge
Rakesh Keshaw
Asked On September 2, 2015 04:51 AM

Hi 

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
            LiveMoteGaugeArray.Scales.Add(GaugeScale)

            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
            GaugeScale.Pointers.Add(GaugePointer1)

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

            Dim GaugeTick2 As New CircularGaugeTick()
            With GaugeTick2
                .TickStyle = TickStyle.MinorInterval
                .TickHeight = 5
            End With
            GaugeScale.Ticks.Add(GaugeTick1)

            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
            GaugeScale.Labels.Add(GaugeLabel1)

            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
            GaugeScale.Labels.Add(GaugeLabel2)

            Me.Form.Controls.Add(LiveMoteGaugeArray)
            intControlNumber = intControlNumber + 1
        Next

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

        BuildMyCircularGauge()

    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
*****************************************************************************************************************************


Anandaraj T [Syncfusion]
Replied On September 4, 2015 08:09 AM

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
[VB]

    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)

        Next
    End Sub

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

Please let us know if you have any concern.

Regards,
Anand


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;