Posts

Showing posts from January, 2013

Bug in Internet Explorer 8 prevents "label for" on secondary radio buttons

Found an interesting bug (and solution) that I'd love to share with you today. Having a razor view produce output similar to the below: <input type="radio" id="ParentCollection_0__ChildCollection_1__1" .../> < label for=" ParentCollection _0__ ChildCollection _1__1" > ... < /label > < input type="radio" id=" ParentCollection _0__ ChildCollection _1__2" .../ > < label for=" ParentCollection _0__ ChildCollection _1__2" > ... < /label > ... a colleague of mine testing the web app found, that the second label ( ParentCollection _0__ ChildCollection _1__2 ) did not cause the corresponding radio button to be checked. Trying the same view in Chrome and Firefox worked flawlessly, however. It turned out, that somehow, Internet Explorer found the ID-field too long, causing it to ignore it (go figure). Anyway, the problem was solved with shortening the ID as such: Dim radioId = ViewData

MVC3+ Auto-adds element ids!

Wow, so I just found this out today, and figured I'd share it with the world before I forgot again ;-). If you're editing a Razor-view and you're asking for an element's ID: Dim ddlFieldId = ViewData.TemplateInfo.GetFullHtmlFieldId(" countryNumber ") ... then just render an element with the same name: Html.DropDownList(" countryNumber ", selectList, "pick one") ... the element will automatically get the ID you requested earlier! Previously, I've gone about it this way: Html.DropDownList("countryNumber", selectList, "pick one", New With {.id = ddlFieldId}) ... but now, it's easier. Isn't that just awesome? :-D Have a great day! // S