Solved

Rewrite code in loop

Posted on 2009-07-16
3
422 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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.   …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

10 Experts available now in Live!

Get 1:1 Help Now