Using a CustomValidator inside the EditTemplate of a FormView

2 posts, 0 answers
  1. Anders
    Anders avatar
    30 posts
    Member since:
    Jul 2013

    Posted 13 May 2015 Link to this post

    Hello

    I try to validate two RadComboBox's which are placed inside the EditTemplate of a FormView. The server-side validation is working fine bit the Client-side is giving me troubles.

    It looks like that the RadComboBox are not yet available when the JavaScript is loaded. On this row of JavaScript:

    var combo = $find("<%= rcbFuelType.ClientID %>");

    I get this error message: Unknown identifier "rcbFuelType".

     

    The FormView is part of UserContrle and I have placed the Javascript inside the asp:content tag where the FormView is. I have also tried to place it inside the EditTemplate without any result.

     

    How can I get the this working?

     

    Anders

    <script language="javascript" type="text/javascript">
        function ClientValidateFueltypes(source, arguments) {
            var combo = $find("<%= rcbFuelType.ClientID %>");
            var combo2 = $find("<%= rcbFuelType2.ClientID %>");
     
            if (combo.get_value() == "N.v.t.") {
                if (combo2.get_value() == "N.v.t.") {
                    arguments.IsValid = false;
                }
            }
        }
    </script>

  2. Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 18 May 2015 Link to this post

    Hi Anders,

    Please have in mind that when a control is placed within a Content Page, RadGrid Template or another container which implements INamingContainer interface, its UniqueID and ClientID are modified, thus making it inaccessible on main Page level. On server-side, you need to use the FindControl method to access the control:
    ( Section Accessing controls in edit/insert mode )
    http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html


    Alternatively, you can use the own event handler of the control itself and cast the sender object to the corresponding type.

    On-client side you can use the OnClientLoad event to get the sender object of the combo or the findControl method:
    http://www.telerik.com/forums/typeerror-a-get_postbackelement%28-%29-is-undefined#VgZ203DhP06ZuX5wx_iRVg

    Hope this helps.


    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top