?
Solved

Rewrite code in loop

Posted on 2009-07-16
3
Medium Priority
?
438 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

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 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