Solved

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

Posted on 2014-02-15
2
515 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
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:murbro
ID: 39862355
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

16 Experts available now in Live!

Get 1:1 Help Now