Event Handling Problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Ther

I have an ASP.NET user control which contains a test panel defined as follows

<asp:Panel ID="TestPanel" Runat="server" /

In the OnInit method I designate an event handler to handle the user controls PreRender event and in the PreRender event handler I create a button as follows

Button _Button = new Button()
_Button.ID = "PRButton"
_Button.Text = "Pre-Render Test"
_Button.Click +=new EventHandler(_Button_Click)
TestPanel.Controls.Add(_Button)

If I add similar code into the Page_Load, the button event successfully fires and is captured by the _Button_Click event handler

However if I click on the button added within the PreRender event handler the debugger steps into the Page_Load and PreRender event handlers but ignors the Button Click event handler

Can any one tell me why this is and also how I can potentially solve this problem

Simply moving the code into the Page_Load is not an option, I have other code that must remain within the Pre_Render event handler

Thank

Doug
 
Hi,

You must add event handlers to dynamic create controls before the page
finished to create all controls. the last event in the page life cycle
that you can do it is Load.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
Back
Top