Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8
This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 by Chris Hart, John Kauffman, David Sussman, Chris Ullman; ISBN: 9780764588501
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2010, 01:12 AM
Authorized User
 
Join Date: Jan 2010
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Differences in how event handlers are created?

Hi All,

general quick question:

I am creating an event handler for the click of a button (eg: protected void Button1_Click(object sender, EventArgs e) - if I type the code from scratch it doesnt work when i generate the page, but if I double click the button on the design form to auto create the event handler it does work. How or why is it so?

I have created a form with 3 buttons and 3 labels as per do it yourself in chapter 9, p.338. I double clicked on the first two buttons to auto create the beginning of the event handler code, but for the third one I wrote the event handler code from scratch. The first two buttons changed the labels as it should have but the third button didnt work.

What exactly happens during the double click of the button to auto create the event handler code that doesnt happen when created manually?

It is not a completely crucial question but it is easier to copy and paste the bulk of the event handler code than it is to have to go back and forth between the design screen of the form and the code behind file.

Thanks,

Chris
 
Old March 8th, 2010, 02:17 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Chris,

It depends on the language you're using. In C#, the markup section of the control is modified:

<asp:Button ..... onclick="Button1_Click" .... />

In VB, in the Code Behind, the handler code is followed by the keyword Handles:

.... Button1_Click(.....) Handles Button1.Click

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 8th, 2010, 05:18 AM
Authorized User
 
Join Date: Jan 2010
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

thanks for that, I can say that I feel adequately stupid for not realising this before.

Thanks,

Chris




Similar Threads
Thread Thread Starter Forum Replies Last Post
parameters in event handlers ajaxbeginner BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 1 December 3rd, 2009 11:59 PM
Event handlers jwebb Visual Basic 2005 Basics 1 June 25th, 2007 08:44 PM
ie7 keycode, event handlers erobb Javascript 0 November 24th, 2006 01:37 PM
Event handlers does not work after some changes geetageetageeta ASP.NET 2.0 Basics 0 March 6th, 2006 04:19 AM
Conflicting Event Handlers chp Excel VBA 3 February 24th, 2006 03:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.