Link to home
Start Free TrialLog in
Avatar of Vido81
Vido81

asked on

Handling Events inside a Web User Control

Hi everyone,

I have just joined this community and I've already got a questions to submit to the experts...

I have created a user control (.ascx) that has some buttons in it. I have dinamically associated each button to an event handler.

I included the user control into an aspx page, and everything went smooth. Unfortunately, though, when I press on the buttons, the event handler doesn't fire.

I am sure missing something in the code of my user control... Could you please tell me how to fire the events directly within the user control?

PLEASE, if you can, provide me with VB code, 'cause I am not very familiar with C.

Thanks a lot!

Vittorio
Avatar of Jason Scolaro
Jason Scolaro
Flag of United States of America image

Hi Vido81,

Can you show us your code for the user control?  How are you adding the user control to a page (are you registering it or using the LoadControl)?

-- Jason
Avatar of Vido81
Vido81

ASKER

Hi Jason,

I register the control in the aspx page with the following tag:

<%@ Register TagPrefix="ucl" TagName="flusso_attivita" Src="flusso_attivita.ascx" %>


This is my control code in the ascx file:

<%@ Control Language="VB" AutoEventWireup="False" CodeFile="flusso_attivita.ascx.vb" Inherits="flusso_attivita" %>
<asp:Table ID="tbl_view" CellSpacing="0" CellPadding="0" CssClass="tblFlussoView" runat="server">
</asp:Table>


I dinamically populate this table in the Page_Load event of the ascx file. The code that populates the table is in another class, so I use this statement to dinamically add a handler:

AddHandler pulsante.Click, AddressOf puls_nuova_attivita_Click

I dinamically add the handler in the Page_Load.


Everything looks fine when I load the aspx page in IE, but when I click on the button, nothing happens!

Thanks.

Vido81,

How are you adding the buttons, does it occur on every page load?  Perhaps you are adding the buttons, but on PostBack they are not being re-created, thus you are losing the event....

-- Jason
ASKER CERTIFIED SOLUTION
Avatar of Elvio Lujan
Elvio Lujan
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vido81

ASKER

Thanks lem2802, you had it right!

I would like to tank Jason as well for his support.