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

Validators?

1 Answer 135 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
James Daresta
Top achievements
Rank 1
James Daresta asked on 26 Mar 2014, 02:39 PM
Can you not use the required field validator or others with the search box? It will not let me.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Mar 2014, 06:22 AM
Hi James Daresta,

Please have a look into the sample code snippet to achieve your scenario.

ASPX:
<telerik:RadSearchBox ID="RadSearchBox1" runat="server" DataSourceID="SqlDataSource1"
    DataTextField="ProductName">
</telerik:RadSearchBox>
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="*" ValidationGroup="Group1"
    ClientValidationFunction="Validate">
</asp:CustomValidator>
<telerik:RadButton ID="RadButton1" runat="server" Text="Validate" CausesValidation="true"
    ValidationGroup="Group1">
</telerik:RadButton>

JavaScript:
<script type="text/javascript">
    function Validate(sender, args) {
        //check your condition and set  args.IsValid to true or false
        var searchbox = $find("<%=RadSearchBox1.ClientID %>");
        if (searchbox.get_text() == "")
            args.IsValid = false;
    }
</script>

Hope this will helps you.
Thanks,
Shinu.
Tags
SearchBox
Asked by
James Daresta
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or