Solved

Rewrite code in loop

Posted on 2009-07-16
3
437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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