+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Changing search box functionality

Changing search box functionality

7 posts, 0 answered
  1. Nick Haworth
    Nick Haworth avatar
    20 posts
    Registered:
    18 Jan 2010
    09 Jun 2010
    Link to this post
    Hi,

    I'd like to extend the telerik SearchBox control to simply not allow an empty search string submission.  I planned to do this by implementing a basic OnClick event that would query the contents of the text box.  However, since the button is just an HTML input button, I can't tie it to a method (as I would with an asp:button control).  Is this possible to do wtihout javascript, or will I need to write my own control to do this?

    Thanks.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Jun 2010
    Link to this post
    Hello Nick Haworth,

    In all cases the click of the input will be processed and you cannot stop it easily. The options are

    1. Use js validation to the TextBox and hide submit button until the text is typed to the TextBox

    sample code

    <script type="text/javascript">
     
        $(document).ready(function() {
        $('div#ff').hide();
        });
        function ValidateTextBox() {
            if ($("queryText").val() == 0) { $('div#ff').hide(); }
            else {
                $('div#ff').show();
            }
        }
     
     
    </script>
     
    <fieldset class="sf_searchBox">
        <asp:Label runat="server" AssociatedControlID="queryText" Text="Search" />
        <asp:TextBox ID="queryText" runat="server" CssClass="sf_searchText"></asp:TextBox>
         
        <div id="ff" class="test1">
        <input type ="button" id="searchButton" runat="server"  class="sf_searchSubmit" value="Search" alt="Search"/>
    </div>
     
    <asp:CustomValidator  Display="Static" ClientValidationFunction="ValidateTextBox" ControlToValidate="queryText"
               runat="server" />
    </fieldset>

    2. The second option would be to check the Text property of queryText TextBox is empty and remove the QueryString from the url which is used by SearchResults control.

    3. Replace the input with another control - ASP.NET button as described in this post.

    All the best,
    Ivan Dimitrov
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  3. Nick Haworth
    Nick Haworth avatar
    20 posts
    Registered:
    18 Jan 2010
    09 Jun 2010
    Link to this post
    Thanks for your reply, but I resolved this by simply redirecting to the previous page in the Page_Load event of the results page, as so:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Request.QueryString("SearchQuery") Is Nothing Then
            Response.Redirect(Request.ServerVariables("HTTP_REFERER"))
        End If
    End Sub

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Jun 2010
    Link to this post
    Hello Nick Haworth,

    Looks like an addition to suggestion 2. Anyway the better option is using client side validation, but the solution you have found is also a good and quick fix.

    Regards,
    Ivan Dimitrov
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  5. David Martinez
    David Martinez avatar
    13 posts
    Registered:
    24 May 2010
    29 Nov 2010
    Link to this post
    How did you write in the Page_Load of the results page, is an external page? I need to do the same but the results page is not physical, is a page created by Sitefinity

    Thanks for your help
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Nov 2010
    Link to this post
    Hello David,

    You need to have a custom control and inside its Page_Load event you can add your custom logic.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  7. David Martinez
    David Martinez avatar
    13 posts
    Registered:
    24 May 2010
    29 Nov 2010
    Link to this post
    Thanks Ivan
Register for webinar
7 posts, 0 answered