Capturing events from a dynamically created control

Capturing events from a dynamically created control

Post by Andres Sos » Fri, 14 Mar 2003 03:55:26



Here is a part of my code.  I'm creating a DropDownList
and placing it in a place holder control.  I would like to
know how to capture events from this controls since
Autopostback is set to true.
    Private Sub initPage()
        '==Local Dims
        Dim oDDL As DropDownList
        '==Create a dropDownlist
        oDDL = New DropDownList()
        oDDL.ID = "ddl_some"
        oDDL.AutoPostBack = True
        oDDL.CssClass = "SomeClass"
        pHdr_printers.Controls.Add(oDDL)
    End Sub
Please help...
 
 
 

Capturing events from a dynamically created control

Post by Edward Car » Fri, 14 Mar 2003 12:50:36


You need to listen for the event.

In C#, you would accomplish this with the following statement, where
MyClickEvent matches the delegate required for an EventHandler.

private void initPage()
{
    DropDownList oDDL = new DropDownList();
    oDDL.ID = "ddl_some"
    oDDL.AutoPostBack = True
    oDDL.Click += new System.EventHandler(MyClickEvent); // Look at this
line.
    oDDL.CssClass = "SomeClass"
    pHdr_printers.Controls.Add(oDDL)

Quote:}

private void MyClickEvent(object sender, EventArgs args)
{
    // Do something here...

}
>     Private Sub initPage()
>         '==Local Dims
>         Dim oDDL As DropDownList
>         '==Create a dropDownlist
>         oDDL = New DropDownList()
>         oDDL.ID = "ddl_some"
>         oDDL.AutoPostBack = True
>         oDDL.CssClass = "SomeClass"
>         pHdr_printers.Controls.Add(oDDL)
>     End Sub



Quote:> Here is a part of my code.  I'm creating a DropDownList
> and placing it in a place holder control.  I would like to
> know how to capture events from this controls since
> Autopostback is set to true.
>     Private Sub initPage()
>         '==Local Dims
>         Dim oDDL As DropDownList
>         '==Create a dropDownlist
>         oDDL = New DropDownList()
>         oDDL.ID = "ddl_some"
>         oDDL.AutoPostBack = True
>         oDDL.CssClass = "SomeClass"
>         pHdr_printers.Controls.Add(oDDL)
>     End Sub
> Please help...


 
 
 

Capturing events from a dynamically created control

Post by Tihomir Trifono » Sat, 15 Mar 2003 01:28:01


look here :
http://www.codeproject.com/aspnet/ASPNetUserControl3.asp

--

Eng. Tihomir Trifonov,
Senior Developer,
Triada Soft Ltd.,
9000, Varna, Bulgaria
9 Veliko Hristov str.
tel/fax +359 52 601-000(602-000)
http://www.triada.bg ,
http://www.triada-soft.bg

Quote:> Here is a part of my code.  I'm creating a DropDownList
> and placing it in a place holder control.  I would like to
> know how to capture events from this controls since
> Autopostback is set to true.
>     Private Sub initPage()
>         '==Local Dims
>         Dim oDDL As DropDownList
>         '==Create a dropDownlist
>         oDDL = New DropDownList()
>         oDDL.ID = "ddl_some"
>         oDDL.AutoPostBack = True
>         oDDL.CssClass = "SomeClass"
>         pHdr_printers.Controls.Add(oDDL)
>     End Sub
> Please help...

 
 
 

1. Problems Capturing Postback Events With Dynamically Created Controls

I hope that I am missing something, but when I create a child control
on my own composite customer control of the ImageButton variety, no
postback events are triggered:

/* in the CreateChildControls method...
ImageButton imgbtnLogin = new ImageButton();
imgbtnLogin.ImageUrl = "/images/login.gif";
imgbtnLogin.ToolTip = "Log into your customer account.";
imgbtnLogin.ID = "btnLogin";
Controls.Add(imgbtnLogin);
cell.Controls.Add(imgbtnLogin);
imgbtnLogin.Click += new
System.Web.UI.ImageClickEventHandler(imgbtnLogin_Click);
*/

But, the following code does work...

Any enlightment greatly appreciated!

2. PutPixel ANSI?

3. how do i dynamically add events for controls that i create dynamically?

4. does plum work for anyone?

5. How to capture dynamically loaded control events?

6. Can someone please review Smalltalk/V 2.0 for OS/2

7. Creating Event Handlers for dynamically created Controls

8. event handler for dynamically created controls

9. Event not being called from a dynamically created control

10. Event handling in dynamically created controls...

11. How to Access ViewState/Events on Dynamically created Controls

12. Dynamically Created LinkButton controls and their events