Button inside a custom control...

T

tranky

Hi boys..
....i've a question for you!

I've a custom control with a button.
Well...
I need to create that:

<mytagprefix:mytag runat="server" onButtonClick="Button_Click">

And in the code behind of this page, i find the Button_Click function.

Ok...
....but how to implements the onButtonClick event in the control side?
What i must do to obtain it?

Please reply me...

....thanx.


tranky
 
T

Tim_Mac

hi,
basically your control has hidden the functionality of the button from the
page containing the control. if you want to access the events of the
button, then you can do 2 things:

in the control, make the button public, and then in the page you can
programatically access the button through the control, and add an event
handler to it as follows:
this.Control1.Button1.Click += new EventHandler(myButtonClick);

OR

you can create a new public event in the control called onButtonClick. this
event will be raised whenever the button click happens, so in a sense it is
'forwarding' the button click event to your new event. with this approach,
your page can use the declarative syntax you have posted below, without
needing to dig into the control to get the button and wire up and event to
it.

i hope this helps
tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top