views:

457

answers:

1

I've got a user control that has an event that I can subscribe to. This works (ignore syntax):

protected void Page_Load(object sender, EventArgs e)
{
   ucControl.Event += new Event(ucControl_Event);
}

but if I removed this line and put the event wire up in my aspx page, it doesn't work. Ex:

<uc1:ucControl id="uc_Control1" runat="server" Event="ucControl_Event" />

I get compilation error when I try it without the ucControl.Event += method.

The error is that the page does not contain a definition for "ucControl_Event" when its obvious that it does.

How do I match my code behind event with the aspx file?

+4  A: 

What's the visibility of your event handler? If it's private then approach 1 works, approach 2 doesn't. If it's protected or public, both work.

David M
your right. VS 05 had created the event handler for me and it had only put void ucControl_Event(object sender, EventArgs e) which made it private. I changed it to protected and worked just fine. Thanks
Miles
You're welcome. Feel free to select my answer then. ;)
David M
hum... thats weird. I had to click on it like 7 times to check it. it must be that good of a answer :)
Miles