locked
Ajax Auto Extender and Custom Validator RRS feed

  • Question

  • User1578452026 posted

    I am using asp.net Grid view which has Text box mapped to autoextender. I am unable to trigger custom validator. Though script is called , it doesnot display the error messgae. Following is the code used.

    <script type="text/javascript">
    var isItemSelected = false;
    function onItemSelected() {
    isItemSelected = true;
    }

    function checkItemSelected(sender,args) {
    alert(sender.id);


    if (!isItemSelected) {
    // alert('inside if');
    // txtInput.focus();

    args.isValid = false;
    alert(args.Value + isItemSelected);
    return args.isValid;
    }
    else {
    //reset isItemSelected
    isItemSelected = false;
    }
    }

    </script>

    <asp:TemplateField >
    <ItemTemplate>
    <asp:TextBox ID="txtEmp" runat="server" ></asp:TextBox>

    <asp:AutoCompleteExtender ServiceMethod="GetEmpList"
    MinimumPrefixLength="1"
    CompletionInterval="10"
    EnableCaching="false"
    CompletionSetCount="1"
    TargetControlID="txtEmp"
    ID="AutoCompleteExtender4"
    runat="server"
    OnClientItemSelected="onItemSelected"
    FirstRowSelected="false"
    >
    </asp:AutoCompleteExtender>


    <asp:CustomValidator id="DisValidator"
    runat="server" ControlToValidate="txtEmp" ValidateEmptyText="false" ClientValidationFunction="checkItemSelected"
    Display="Dynamic" ErrorMessage="Please select item" ForeColor ="Red" Enabled="true">*</asp:CustomValidator>
    </ItemTemplate>

    Sunday, March 8, 2015 12:05 PM

Answers

  • User1644755831 posted

    Hello VjKishan,

    VJKishan

    Though script is called , it doesnot display the error messgae. Following is the code used.

    1. If your script is called then check the values of sender. sender might not have a property called id or there might a mistake in how to write id.

    2. Try using developer tools (F12) and check the value of sender. it should not be undefined and sender.id also should not be undefined other wise the alert(sender.id); will throw exception and your message won't show.

    3. if sender is not undefined then try doing this once alert(sender); you should get [object][object] in the message as result.

    Hope this helps.

    With Regards,

    Krunal Parekh.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 10, 2015 3:20 AM