handling a button's click event

P

PJ6

I've added a button to a class inheriting from System.Web.UI.Control and
want to handle (pass on) its click event to the page that contains it.

Coming from a WinForms background, I thought this (below) would work. It
doesn't. A break point on btn_Click isn't even hit.

Is there a way to do this?

Paul

Private Sub btn_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btn.Click
Me.OnClick(New EventArgs)
End Sub

Public Event Click(ByVal sender As Object, ByVal e As EventArgs)

Protected Overridable Sub OnClick(ByVal e As EventArgs)
RaiseEvent Click(Me, e)
End Sub
 
S

S. Justin Gengo

PJ6,

Without knowing what your control contains this is difficult... But, a short
answer might be to do the following:

Would you be able to inherit from a button instead of just a generic
control? Then you'd have all the postback hookup code inherent in the object
instead of having to create it yourself...

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
P

PJ6

What I have now is a table with one row with three cells. Each cell has some
"pretty" background in it, and in the center cell there is some text, or, if
need be, a real button. It's essentially a customized button that should act
like a button control.

I could in theory inherit button and override render, but I think that still
leaves me with a problem - this control needs to raise a click event
server-side in its containing form. Yes, I can manually raise the click
event in with OnClick, but from where do I fire that? A contained button's
click event? That doesn't work, the control - whether it be inherited from
Control or Button - refuses to handle it.

Please tell me about postback hookup code.

Paul
 

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

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top