Wrox Programmer Forums
BOOK: Beginning ASP.NET Web Pages with WebMatrix
This is the forum to discuss the Wrox book Beginning ASP.NET Web Pages with WebMatrix by Mike Brind, Imar Spaanjaars ; ISBN: 978-1-1180-5048-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Web Pages with WebMatrix 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 August 26th, 2013, 08:53 PM
Registered User
Join Date: Aug 2013
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 5 Helpers

Hi - Love the book so far, found a couple of errors here and there but noticed that they were addressed in the forums.

I may be pedantic but I am not sure I understand the reason for this code:

@helper Selected(string option, string value){
if(HttpContext.Current.Request[option] != null){
var values = HttpContext.Current.Request[option].Split(',');
What's the point of selected=\"selected\" there?
When I look into source code I see something like
<option         selected=\"selected\">
To my knowledge (and that means days from diving into HTML 15+ yrs ago) <option selected> is the right form according to W3C.

So I used the following instead
        // This seem to work just fine
        //   <text>selected</text> 

        // and this works as well
End result is
<option selected>

Pretty much the same deal with Checked helper.

Am I missing something?

Old August 26th, 2013, 09:20 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

No, you're not missing something. In the old days, selected was just fine. Then in HTML 4, that required all attributes to have a value, selected="selected" was required. However, now with HTML 5, we're back to empty attributes again, so just selected works fine and is valid HTML.

The backslashes to escape the double quotes aren't needed (and are actually a bug in this code). Normally, inside a C# string, you need them or else the double quote would terminate the string prematurely. However, in this example, with the text being inside a pair of <text> tags, you can use double quotes as is without the need to escape them.

So, your solution works perfectly well, as would selected="selected" (since a value on the attribute is still allowed).

Hope this helps,

Imar Spaanjaars
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!
The Following User Says Thank You to Imar For This Useful Post:
sc0ri0n (August 27th, 2013)
Old August 27th, 2013, 07:16 PM
Registered User
Join Date: Aug 2013
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts

Makes perfect sense, thanks!

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML Helpers' parameters Gudni BOOK: Beginning ASP.NET Web Pages with WebMatrix 2 September 18th, 2012 03:54 AM
Paginated List (Helpers) error Mr. Bill BOOK: Professional ASP.NET MVC 2 6 March 4th, 2011 06:25 AM
Html helpers doesn't work on site.master Gabor66 BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 1 November 4th, 2009 11:29 AM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM
Why Countries in Helpers? plb BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 February 22nd, 2007 07:14 PM

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