Copied to clipboard

Flag this post as spam?

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


  • Fernando Camillo 41 posts 82 karma points
    Oct 01, 2010 @ 14:35
    Fernando Camillo
    0

    Backend user controls: How to set-up validation for then?

    Hi.

    I've made a very simple user control for tests in the backend. It's a combobox with 3 values:
    - Choose (empty string)
    - Male ("M" string)
    - Female ("F" string)

    The control is working, the data is being saved in umbraco database. However, if I check the "required" option for this type in the document type properties, umbraco ignores this and allows contents to be saved with this field empty.

    What can I do to handle validation for my backend user control?

    Thanks!

    Fernando

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Oct 01, 2010 @ 15:02
    Aaron Powell
    0

    I believe you can use the ValidationPropertyAttribute (http://msdn.microsoft.com/en-us/library/system.web.ui.validationpropertyattribute ) but I don't think it's 100% reliable. 

    I'd recommend that you do validation by putting your own validation controls into the User control. I don't know how (or if it's possible) to work out from a data type whether it is set as a 'required' property on a document type (without a lot of nasty hacks :P)

  • Fernando Camillo 41 posts 82 karma points
    Oct 01, 2010 @ 18:34
    Fernando Camillo
    0

    Hi Slace.

    Thanks! You're right. I used a "Required Field Validator" inside the user control, and now it works like a charm!

    Thank you again for the help.

    Fernando

  • Giacomo Cosenza 16 posts 36 karma points
    May 03, 2011 @ 12:41
    Giacomo Cosenza
    0

    Hi Fernando, you used Required Field Validator and works? How? 

    Thanks

    G.

  • Fernando Camillo 41 posts 82 karma points
    May 12, 2011 @ 15:33
    Fernando Camillo
    0

    Hi Giacomo.

    Here goes the code:

    <asp:RequiredFieldValidator ID="myFieldRequiredValidator" runat="server" 
    Display="None" EnableClientScript="false"
    ControlToValidate="myDropDownList"
    ErrorMessage="The field MyField is mandatory!">
    </asp:RequiredFieldValidator>

    However, it doesn't obey the Umbraco checkbox "required". It's always required.

    Fernando

Please Sign in or register to post replies

Write your reply to:

Draft