|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Creating dynamic controls with events Hello everyone, I wonder if it is possible to assign an event management control to a dynamically created AFTER the Page_Load? The control is created as expected but the events are not taken into account. Thank you in advance. |
#2
| |||
| |||
Re: Creating dynamic controls with events Easy way to check whether created dynamic controls are working appropriately you need to create window application that need to handle events their Attributes need not to be come in between while making any changes and adding controls dynamically, which will handle events, to that window. Code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim btn As Button For i As Integer = 0 To 10 btn = New Button btn.Text = "Button" & i btn.ID = "Button" & i AddHandler btn.Click, AddressOf btn_Click MyPanel.Controls.Add(btn) Next End Sub Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Response.Write("You clicked " & CType(sender, Button).ID) End Sub |
#3
| |||
| |||
Re: Creating dynamic controls with events You can get GetEvent method on the Type to get the EventInfo that represents the event. Start creating controls in the Page.PreInit event. Move your existing code from the Load event to PreInit, and look to see if the page is posting back. If not, do what you are currently doing. If it is posting back, save the data about your controls (i.e. how many and names) in Session variables.Once you have that, you can call the AddEventHandler method on the EventInfo instance to add the event to the control. |
#4
| |||
| |||
Re: Creating dynamic controls with events please check the code and try for your reference. Code: Dim t As Textbox = pnlPanel.FindControl("txtText") If t IsNot Nothing Then t.Text = "Found Control! Else Error message End If |
![]() |
|
Tags: dynamic control, dynamic page load, event management, events |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
What are dynamic controls in DHTML | Maximiliano2 | Software Development | 5 | 13-11-2010 06:30 AM |
All day events one day out | Steadfast | Portable Devices | 4 | 13-10-2010 11:22 AM |
Creating Controls In A Loop | technika | Software Development | 5 | 05-02-2010 10:34 PM |
Creating dynamic pages with asp to redirect | Isdel | Software Development | 3 | 20-11-2009 10:39 PM |
What are those controls that do not have events? | Chandrakant81 | Software Development | 3 | 27-02-2009 10:40 PM |