title: Telerik ASP.Net Radgrid show / hide filters
body: <p>I am building an ASP.Net Telerik Radgrid at runtime based on a passed in configuration so there is no radgrid tag on my ASPX page. I am trying to implement functionality where I can add a button to the header of the grid that will show or hide the column filters.</p>
  
  <p>I am using a <a href="http://www.telerik.com/help/aspnet-ajax/grid-commanditemtemplate.html" rel="nofollow">Command Item Template</a> to provide the show/hide button which is appearing but when I click the button to show or hide the filters with the <code>ShowHideFilters</code> Javascript method using the <a href="http://www.telerik.com/help/aspnet-ajax/grid-get-mastertableview.html" rel="nofollow">grid.get_masterTableView()</a> function it can not find the <code>get_masterTableView()</code> method on the grid object.</p>
  
  <p>Any idea why this method is missing or a better alternative to achieve the behavior I require?</p>
  
  <p><a href="http://www.telerik.com/help/aspnet-ajax/grid-get-mastertableview.html" rel="nofollow">Telerik Radgrid Client API </a></p>
  
  <p><strong>JavaScript example from Telerik API</strong></p>
  
  <pre><code>function getMasterTableView() {
      var grid = $find("&lt;%=RadGrid1.ClientID %&gt;");
      var masterTableView = grid.get_masterTableView();              
  }  
  </code></pre>
  
  <p><strong>Page</strong></p>
  
  <pre><code>&lt;%@ Page Language="VB" AutoEventWireup="false" CodeFile="ShowGrid.aspx.vb" Inherits="ShowGrid" %&gt;
  
  &lt;%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;form id="ShowGrid" runat="server"&gt;
  
          &lt;telerik:RadScriptManager ID="ScriptManager" runat="server"&gt;
          &lt;/telerik:RadScriptManager&gt;
  
          &lt;telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"&gt;
              &lt;AjaxSettings&gt;
                  &lt;telerik:AjaxSetting AjaxControlID="ConfigureGrid"&gt;
                      &lt;UpdatedControls&gt;
                          &lt;telerik:AjaxUpdatedControl ControlID="ConfigureGrid" LoadingPanelID="AjaxLoadingPanel" /&gt;
                      &lt;/UpdatedControls&gt;
                  &lt;/telerik:AjaxSetting&gt;
              &lt;/AjaxSettings&gt;
          &lt;/telerik:RadAjaxManager&gt;
  
          &lt;telerik:RadAjaxLoadingPanel ID="AjaxLoadingPanel" runat="server"/&gt;
  
          &lt;asp:SqlDataSource ID="PrimaryDataSource" runat="server"/&gt;
      &lt;/form&gt;
  
      &lt;script type="text/javascript"&gt;
  
          function ShowHideFilters()
          {
              var grid = document.getElementById("ConfigureGrid")
              if (grid)
              {
                  var masterTableView = grid.get_masterTableView();
                  window.alert(masterTableView.id)
              }
  
              window.alert(grid.id)
          }
  
      &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Code behind</strong></p>
  
  <p>Build the grid from the ground up in the Page_Init</p>
  
  <pre><code>Protected Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
  
      Try
          BuildConfiguration()
          CreateTitleObject()
          CreateRadFilter()
          LoadDataSource()
          CreateRadGrid()
      Catch ex As Exception
          CreateExceptionDisplay(ex)
      End Try
  
  End Sub
  </code></pre>
  
  <p><strong>Item template</strong></p>
  
  <pre><code>Friend Class RadGridCommandItemFilterTemplate
      Implements ITemplate
  
      Protected showHideFilterButton As Button
  
      Public Sub New()
          MyBase.New()
      End Sub
  
      Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
          showHideFilterButton = New Button
          showHideFilterButton.EnableTheming = True
          showHideFilterButton.ID = "showHideFilterButton"
          showHideFilterButton.Text = "Show / Hide Filters"
          showHideFilterButton.CommandName = "ShowHideFilters"
          showHideFilterButton.OnClientClick = "ShowHideFilters()"
          container.Controls.Add(showHideFilterButton)
      End Sub
  
  End Class
  </code></pre>
  
  <p><strong>Adding the item template</strong></p>
  
  <pre><code>grid.MasterTableView.CommandItemTemplate = New RadGridCommandItemFilterTemplate
  </code></pre>