Solved

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

Posted on 2014-02-15
2
519 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:Murray Brown
[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
2 Comments
 
LVL 15

Accepted Solution

by:
ChloesDad earned 500 total points
ID: 39861900
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:Murray Brown
ID: 39862355
Thanks
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

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