471,853 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

handling a button's click event

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

Nov 19 '05 #1
3 2591
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
"PJ6" <no****@nowhere.net> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #2
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

"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:ea*************@TK2MSFTNGP10.phx.gbl...
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
"PJ6" <no****@nowhere.net> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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


Nov 19 '05 #3
PJ6,

This article will explain what you need to do:

http://msdn.microsoft.com/library/de...EventModel.asp
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"PJ6" <no****@nowhere.net> wrote in message
news:Ob**************@TK2MSFTNGP12.phx.gbl...
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

"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:ea*************@TK2MSFTNGP10.phx.gbl...
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
"PJ6" <no****@nowhere.net> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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



Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by John Fereira | last post: by
2 posts views Thread by Marinos Christoforou | last post: by
reply views Thread by luca | last post: by
12 posts views Thread by Jack Russell | last post: by
8 posts views Thread by Louis | last post: by
5 posts views Thread by Klaudiusz Bryja | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.