Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

handling a button's click event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PJ6 - 15 Oct 2005 19:14 GMT
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. Justin Gengo - 15 Oct 2005 21:43 GMT
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...

Signature

Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
                           Nietzsche

> 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.
[quoted text clipped - 16 lines]
>        RaiseEvent Click(Me, e)
>    End Sub
PJ6 - 15 Oct 2005 22:14 GMT
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

> PJ6,
>
[quoted text clipped - 25 lines]
>>        RaiseEvent Click(Me, e)
>>    End Sub
S. Justin Gengo - 16 Oct 2005 02:40 GMT
PJ6,

This article will explain what you need to do:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbco
nWebFormsEventModel.asp


Signature

Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
                           Nietzsche

> 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,
[quoted text clipped - 41 lines]
>>>        RaiseEvent Click(Me, e)
>>>    End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.