2015-12-21 29 views
0

我想在用户单击gridview标题中的过滤器图标时显示/隐藏文本框。最初,文本框是隐藏的。当我点击图标时,文本框出现一秒钟,然后看起来页面被刷新并且文本框再次被隐藏。 这是HTML:文本框仅在javascript函数运行后暂时显示

<asp:TemplateField HeaderText="Group Name"> 
<HeaderTemplate> Group Name 
    <asp:ImageButton ID="uggvGroupFilter" runat="server" ImageUrl="Images/filter.png" OnClientClick="ShowHideFilterTxtBox('uggvTxtNameFilter')" /> 
    <asp:TextBox ID="uggvTxtNameFilter" runat="server" AutoPostBack="true" style="display:none;" ClientIDMode="Static" OnTextChanged="uggvGridFilter_TextChanged"> 
    </asp:TextBox> 
</HeaderTemplate> 
<ItemTemplate> 
    <asp:Label ID="uggvLblGroupName" runat="server" Text='<%# Bind("GroupName") %>'></asp:Label> 
</ItemTemplate> 
</asp:TemplateField> 

这是JavaScript函数:

function ShowHideFilterTxtBox(filterID) { 
    var obj = document.getElementById(filterID); 
    if (obj.style.display == "none") { 
    obj.style.display = "block";   
    } else { 
    obj.style.display = "none";    
    } 
} 

这是我的文档准备功能:

$(document).ready(function() { 
    //Configure the DropDownBox using the 'chosen' jquery plugin 
    $(".chosen-single").chosen({ 
    search_contains: true, 
    width: "200px", 
    no_results_text: "Sorry, no match!" 
    });   
}); 

我需要把一些东西在我的文档准备功能呢? 为什么文本框的样式只设置了一秒钟,然后返回到'无'的原始样式显示?

谢谢。

回答

0

在您的客户端功能中执行return false

function ShowHideFilterTxtBox(filterID) { 
     var obj = document.getElementById(filterID); 
     if (obj.style.display == "none") { 
      obj.style.display = "block";   
     } 
     else { 
      obj.style.display = "none";    
     } 
    return false; 
} 

当你骂

OnClientClick="return ShowHideFilterTxtBox('uggvTxtNameFilter')" 
+0

谢谢!这工作。最初,我在'OnClientClick'上有'return false',但没有'return'。你为什么需要这样做? –

+0

如果它在OnClientClick中没有返回工作,只需将其删除即可。 :) – Shyju

+0

不,我需要这两个工作。我只是想知道为什么这个功能需要回报。这一切。 –