This is a migrated thread and some comments may be shown as answers.

Using a CustomValidator inside the EditTemplate of a FormView

1 Answer 88 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 13 May 2015, 08:51 AM

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>

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 18 May 2015, 07:46 AM
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
Tags
General Discussions
Asked by
Anders
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or