开发者

Problem when attaching a Custom Validator to a control dynamicly

Anyone have an idea why this code doesnt work?

<script type="text/javascript">
    function BookDeskValidation(source, arguments) {
        var deskCombo = $find("<%=RadComboBoxDesk.ClientID%>");
        var bookCombo = $find("<%=RadComboBoxBook.ClientID%>");
        if (bookCombo.get_text() != "" && deskCombo.get_text() == "") {
            arguments.IsValid = false;
        }
        else {
            arguments.IsValid = true;
        }
    }

    function AttachValidator(combobox) {
        var validator = document.getElementById("<%= CustomValidatorDeskBook.ClientID %>");
        validator.controltovalidate = combobox.get_id();
        validator.ClientValidationFunction = "BookDeskValidation";
        ValidatorHookupControl(combobox, validator);
    }
</script>

<td>Book:&nbsp;</td>
        <td>
            <telerik:RadComboBox ID="RadComboBoxBook" runat="server" OnClientFocus="AttachValidator">
            </telerik:RadComboBox>
        </td>

<td width="70">Desk:&nbsp;</td>
            <td width="100">
                <telerik:RadComboBox ID="RadComboBoxDesk" runat="server" OnClientFocus="AttachValidator">
                </teler开发者_JAVA技巧ik:RadComboBox>
            </td>
<asp:CustomValidator ID="CustomValidatorDeskBook" runat="server" 
            ErrorMessage="Error" 
            ClientValidationFunction="BookDeskValidation" ForeColor="Red">*</asp:CustomValidator>

The OnClientFocus is fire but it then the custom validator doesnt seem to be attached because no validation is done when I exit the control on which the validator should be attached.

Thank you!


Ok I managed to get this work. Here`s what I did. If anyone knows a better way to do it or if what I did to solve the problem is not right please let me know!

So here's what I did:

<script type="text/javascript">
    function BookDeskValidation(source, arguments) {
        var deskCombo = $find("<%=RadComboBoxDesk.ClientID%>");
        var bookCombo = $find("<%=RadComboBoxBook.ClientID%>");
        if (bookCombo.get_text() != "" && deskCombo.get_text() == "") {
            arguments.IsValid = false;
        }
        else {
            arguments.IsValid = true;
        }
    }

    function AttachValidator(combobox) {
        var validator = document.getElementById("<%= CustomValidatorDeskBook.ClientID %>");
        validator.ControlToValidate = combobox.get_id();
    }

    function EnableValidator(combobox) {
        var validator = document.getElementById("<%= CustomValidatorDeskBook.ClientID %>");
        ValidatorEnable(validator, true);
    }
</script>

<td>Book:&nbsp;</td>
<td>
      <telerik:RadComboBox ID="RadComboBoxBook" runat="server" OnClientFocus="AttachValidator" OnClientDropDownClosed="EnableValidator">
      </telerik:RadComboBox>
</td>

So basicly I got rid of the ValidatorHookupControl function and replaced it with ValidatorEnable on the event OnClientDropDownClosed

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜