Solved

ASP.net VB.net AddHandler to timers that are dynamically added

Posted on 2014-02-15
2
514 Views
Last Modified: 2014-02-15
Hi. The code below is used to add a number of GridViews and Timers to update panels that are then added to a Table. How do I add a tick event handler to each timer that runs certain code in VB.net


    Dim oGridView As New GridView
        oGridView.ID = "xChartGridView" & CStr(oChartGridViewID_Counter)
        Dim oTimer As New Timer
        oTimer.ID = "xTimer" & CStr(oChartGridViewID_Counter)
        oTimer.Interval = "5000"
        Dim dt As DataTable = SQL_Data_Table.GetSQLDataTable(oConnectionString, SQL)
        Dim pvt As New Pivot(dt)
        oGridView.DataSource = pvt.PivotData(RowFields, DataField, oAggregate, ColumnFields)
        oGridView.DataBind()
      up.ContentTemplateContainer.Controls.Add(oGridView)
        up.ContentTemplateContainer.Controls.Add(oTimer)
        T.Rows(0).Cells(oColumn).Controls.Add(up)
        T.Rows(0).Cells(oColumn).Controls.Add(oGridView)
0
Comment
Question by:murbro
2 Comments
 
LVL 15

Accepted Solution

by:
ChloesDad earned 500 total points
Comment Utility
You should be able to add a handler manually after creating the timer

   AddHandler oTimer.Tick, AddressOf oTimer_Tick

You may also need to have the timer created as a private variable in the form, as if its created with a local variable in a subroutine then at the end of the subroutine it will no longer be in scope and hence may not trigger.

eg Private with events oTimer as Timer

Then create the timer and the handler when you need them.

You should also remove the handler when you no longer need it

RemoveHandler oTimer.Tick, AddressOf oTimer_Tick
0
 

Author Closing Comment

by:murbro
Comment Utility
Thanks
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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

17 Experts available now in Live!

Get 1:1 Help Now