Hide/Show SearchBox from javascript

3 posts, 0 answers
  1. Mickael
    Mickael avatar
    24 posts
    Member since:
    Oct 2014

    Posted 15 Oct 2014 Link to this post


    I am trying to toggle the visibility of a searchbox on my page using a button.
    but for some reason the searchbox never disappear.

        OnClientClick="Search_Click()" />
        <DropDownSettings Height="400" Width="300" />
        <WebServiceSettings Path="Main.aspx" Method="GetResults" />
    <script type='text/javascript'>
        function Search_Click() {
        function toggle_visibility(id) {
            var e = document.getElementById(id);
            if (e.style.display == 'block')
                e.style.display = 'none';
                e.style.display = 'block';

    From the code behind if I change the Visibility, it works.
    But I do not want to do this from the code behind. I need to do it from client-side javascript.
  2. Dimitar Terziev
    Dimitar Terziev avatar
    1266 posts

    Posted 16 Oct 2014 Link to this post


    You could use the following implementation of the toggle_visibility function:
    function toggle_visibility(id) {
       $telerik.$("#"+ id).toggle();

    Dimitar Terziev

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  3. Mickael
    Mickael avatar
    24 posts
    Member since:
    Oct 2014

    Posted 16 Oct 2014 in reply to Dimitar Terziev Link to this post

    Even with your code I could not get it to work, so I investigated the page behaviour instead.
    In the end I had to switch from the asp:ImageButton to a simple 'img' with a 'onclick' because what happened was that the ImageButton was doing a postback and thus cancelling the visilibity toggle.

    Thanks for your help.
Back to Top