Solved

Rewrite code in loop

Posted on 2009-07-16
3
426 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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 …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now