Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 October 25th, 2011, 12:18 AM
Authorized User
 
Join Date: Sep 2011
Posts: 41
Thanks: 3
Thanked 4 Times in 3 Posts
Default Chp 15, += ?

Hi,

Page 542:

PostBack.Text += handlerName

NoPostBack.Text += handlerName

QUESTION: why is "+=" needed and not just "=" ? If I coded this myself, I would never think to use the + ...

???
 
Old October 25th, 2011, 11:11 AM
Registered User
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hello everyone

Chp 15 is tough. I saw this also but going to pass on it. But now that I see it posted, yes, I am wondering now also.

There is nothing in the labels, so why does the label.Text need a "+=" to work properly?
 
Old October 29th, 2011, 11:08 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi nanonerd and JWalsh,

Take another look at Chapter 5, page 156. += is used to append a new value to whatever was already there in the label. With using just =, you would overwrite the existing value.

On the first event, the label is indeed empty so an equals sign would suffice. However, since this method is called multiple times during the same request, an equals sign would overwrite the previous value on each call. This in turn would only output the name of the very last event that executed. By using +=, the Text property is expanded on each call, giving you a list of the event handlers that have been called.

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chp 6 Login Page majeedkhan BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 December 22nd, 2010 05:19 AM
Chp Earthquakes pmlco BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 0 February 22nd, 2010 12:05 PM
listing 15-15 pg(568) DyerOppenheimer BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 February 13th, 2008 01:41 PM
Chp 14 e-commerce JamesA BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 September 3rd, 2004 06:14 PM





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