Solved

Rewrite code in loop

Posted on 2009-07-16
3
435 Views
Last Modified: 2013-11-08
I am trying to rewrite the following code more sufficiently:

Chart1.DataBind()
Chart2.DataBind()

Me.Chart1.CallbackStateContent = CallbackStateContent.SeriesDataOnly
Me.Chart2.CallbackStateContent = CallbackStateContent.SeriesDataOnly
Me.Page.ClientScript.RegisterStartupScript(GetType(Dundas.Charting.WebControl.Chart), "Chart2_Callback", "window.setInterval(""" + Me.Chart2.CallbackManager.GetCallbackAsyncMethodReference(Timer, "") + """, 500);", True)
Me.Page.ClientScript.RegisterStartupScript(GetType(Dundas.Charting.WebControl.Chart), "Chart1_Callback", "window.setInterval(""" + Me.Chart1.CallbackManager.GetCallbackAsyncMethodReference(Timer, "") + """, 500);", True)

This is what I came up with. Here's my question: How can I replace the hardcoded value "Chart2_Callback" (line 6 below) with a variable to dynamilcally call either "Chart2_Callback" or "Chart1_Callback" ?


Dim charts() As Chart = {Chart1, Chart2}
        For i As Integer = 0 To charts.Length - 1
            charts(i).DataBind()
            charts(i).CallbackStateContent = CallbackStateContent.SeriesDataOnly
            Me.Page.ClientScript.RegisterStartupScript(GetType(Dundas.Charting.WebControl.Chart), "Chart2_Callback", "window.setInterval(""" + charts(i).CallbackManager.GetCallbackAsyncMethodReference(Timer, "") + """, 500);", True)

        Next
0
Comment
Question by:JessyRobinson1234
3 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 24870688
"Chart1_Callback" and "Chart2_Callback" being string values ...
simply have string array like you have charts()...like chartString()
then reference it using chartString(0) / chartString(1)
hope i got the question correct....
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 24871059
If the name of the callmack method always follow the same pattern:

chars(i).ID + "_Callback"
0
 

Accepted Solution

by:
JessyRobinson1234 earned 0 total points
ID: 24874150
This code is working without errors on page_load but the strange is that the charts disappear in runtime after the code gets executed. Can you not refresh 2 charts simultaneously on page load?

Dim charts() As Chart = {Chart1, Chart2}
        For i As Integer = 0 To charts.Length - 1
            charts(i).DataBind()
            charts(i).CallbackStateContent = CallbackStateContent.SeriesDataOnly
            Me.Page.ClientScript.RegisterStartupScript(GetType(Dundas.Charting.WebControl.Chart), charts(i) + "_Callback", "window.setInterval(""" + charts(i).CallbackManager.GetCallbackAsyncMethodReference(Timer, "") + """, 500);", True)

        Next
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question