Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rob Watkins 343 posts 593 karma points
    Apr 13, 2012 @ 13:14
    Rob Watkins
    0

    Umbraco 4.7, usercontrol macros, hyphens and validator client scripts

    Just found a really weird error, I can't work out if it's Umbraco specific or a .NET bug.

    I developed a usercontrol for a registration form, which had a number of standard ASP.NET validators on it.

    However, I was getting script errors, and this is why:

    When ASP.NET generates client side script for validators, it seems to create a load of dynamic Javascript, including setting up some variables that are named the full ClientID of the validator control.

    Now, something - I think Umbraco? - is setting the ID of the embedded usercontrol to be the filename of the .ASCX file.

    This is fine, except when your user control has hyphens in - e.g. registration-form.ascx

    What happens then is that everything seems to work - it's a perfectly valid ID for an HTML element, and all the serverside stuff seems to work fine too, but it means the automatic validator scripts will contain things like:

    var page001_ctl001_ph001_registration-form_1_ctl004 = document.all[...];

    ...which is not valid Javascript due to the hyphen in the variable name.

    As I said, pretty obscure, and you might not even notice it as the server side validation all still works!

  • Grant Thomas 291 posts 324 karma points
    Apr 13, 2012 @ 14:14
    Grant Thomas
    0

    Personally my solution would be to rename the file to be more appropriate. Granted, I feel pretty strongly about file system object naming (specially within a programming environment, but it's for this very reason: a user can name their day-to-day files as they want, but as programmers we have to think that all this kind of stuff can happen, and knowing that a hyphen in a variable name isn't going to work in most contexts (and possibly complicate things in many more ways) should kind of be a deterrant to doing so.

    This doesn't even mention standards, which, if we were to consider, would dictate this a weird naming convention for files that would have a corresponding type. Since you could not name the type with a hyphen, why name its file in such a way? It's still an identifier of sorts. In my opinion this is not a bug in either Umbraco or .NET, but instead is a human error.

  • Rob Watkins 343 posts 593 karma points
    Apr 13, 2012 @ 14:18
    Rob Watkins
    0

    Oh yeah, I renamed the file, but thought the thread might prevent someone else from going mad :o)

    Although if it had been me, I'd have written the validator code using a hashmap rather than hardcoded variables, even auto generated ones :o)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies