title: Filter TextBox value disappear after postback telerik:RadGrid
body: <p>I am trying to filter data by column but after postback the data is getting removed from textbox    </p>
  
  <pre><code>&lt;%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
      CodeFile="DynamicTestCaseReport.aspx.vb" Inherits="DynamicTestCaseReport" %&gt;
  
  &lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %&gt;
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"&gt;
      &lt;link rel="shortcut icon" href="Images/TM32.ico" /&gt;
      &lt;link href="css/style.css" rel="stylesheet" type="text/css" /&gt;
      &lt;link href="css/TestMagic.css" rel="stylesheet" type="text/css" /&gt;
      &lt;link href="css/calendar.css" rel="stylesheet" type="text/css" /&gt;
      &lt;link href="css/calendar.css" rel="stylesheet" type="text/css" /&gt;
      &lt;sript runat="server"&gt;&lt;/sript&gt;
  
      &lt;asp:ToolkitScriptManager ID="ToolScriptManager1" runat="server"&gt;
      &lt;/asp:ToolkitScriptManager&gt;
  
      &lt;table id="tblData" cellspacing="0" cellpadding="0" width="100%" border="0" runat="server"&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;div id="rowlblError" runat="server" align="center"&gt;
                      &lt;asp:Label ID="lblError" runat="server" CssClass="LabelMessage"&gt;
                      &lt;/asp:Label&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td align="center" class="Title"&gt;
                  &lt;asp:Label ID="lblDisplayHeader" runat="server"&gt;&lt;/asp:Label&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td align="center"&gt;
                  &lt;asp:Label ID="lblMsg" runat="server" CssClass="LabelMessage"&gt;&lt;/asp:Label&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
  
                  &lt;asp:Label ID="lblTemplate" runat="server" Text="Template Name : "&gt;&lt;/asp:Label&gt;
                  &lt;asp:DropDownList ID="cboTemplate" runat="server" AutoPostBack="True" OnSelectedIndexChanged="cboTemplate_SelectedIndexChanged"
                      CssClass="text1" Width="200px"&gt;
                  &lt;/asp:DropDownList&gt;
  
              &lt;/td&gt;
  
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style="padding-top: 10px;"&gt;
                  &lt;asp:CheckBoxList Width="100%" runat="server" ID="chkFields" DataTextField="Column_name"
                      DataValueField="Column_name" ToolTip="Please select data fields for report generation."
                      RepeatColumns="4" RepeatDirection="Horizontal" RepeatLayout="Table" BorderStyle="Solid"
                      TextAlign="Right" BorderWidth="1" BorderColor="Black" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
  
              &lt;td style="padding-top: 10px;"&gt;
                  &lt;table style="width: 990px;"&gt;
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;asp:Label ID="lblTemplateName" runat="server" Text="Enter Template Name : "&gt;&lt;/asp:Label&gt;
                              &lt;asp:TextBox ID="txtTemp" runat="server" MaxLength="100" Columns="22" Width="150"&gt;&lt;/asp:TextBox&gt;
                              &lt;asp:Button ID="btnSaveTemplate" runat="server" Text="Save Template" CssClass="BigBtn" /&gt;
                          &lt;/td&gt;
  
                          &lt;td align="right" style="padding-left: 200px;"&gt;
  
                              &lt;asp:Button ID="btnShowGrid" runat="server" Text="Generate"
                                  CssClass="NormalBtn" /&gt;
                              &lt;asp:Button ID="btnCancel" runat="server" Text="Cancel"
                                  CssClass="NormalBtn" /&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
  
  
              &lt;/td&gt;
  
              &lt;%--      &lt;td align="left" style="padding-right: 200px;"&gt;
                  &lt;asp:Button ID="btnShowGrid" runat="server" Text="Generate"
                      CssClass="NormalBtn" /&gt;
                  &lt;asp:Button ID="btnCancel" runat="server" Text="Cancel"
                      CssClass="NormalBtn" /&gt;
              &lt;/td&gt;--%&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td style="padding-top: 10px;"&gt;
  
                  &lt;div id="gridDiv" runat="server" style="z-index: 1; overflow: scroll;"&gt;
  
                      &lt;telerik:RadGrid ID="gridData" runat="server" Visible="true" OnGridExporting="grid_GridExporting"&gt;
                      &lt;/telerik:RadGrid&gt;
  
                  &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td align="right" style="padding-top: 10px;"&gt;
                  &lt;div id="gridDiv1" runat="server"&gt;
                      &lt;asp:Button ID="btnEmailReport" runat="server" Text="Email Report"
                          CssClass="BigBtn" /&gt;
                      &lt;asp:Button ID="btnExcel" runat="server" Text="Export to Excel"
                          CssClass="BigBtn" /&gt;
                     &lt;asp:Button ID="btnECSV" runat="server" Text="Export to CSV"
                          CssClass="BigBtn" /&gt;
                        &lt;asp:Button ID="btnEPDF" runat="server" Text="Export to PDF"
                          CssClass="BigBtn" /&gt;
                  &lt;/div&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>CS code i have done necessary setting if not please correct me : </p>
  
  <pre><code>    Partial Class DynamicTestCaseReport
      Inherits System.Web.UI.Page
      Dim objGeneral As TestMagic.General
      Protected Form1 As New System.Web.UI.HtmlControls.HtmlForm
      Dim flag As Boolean = False
      Dim flagcheck As Boolean = False
      Dim common As TestMagic.General = New TestMagic.General()
      Dim ServerPath As String = Server.MapPath("ReportViewer")
  
  #Region " Web Form Designer Generated Code "
  
      'This call is required by the Web Form Designer.
      &lt;System.Diagnostics.DebuggerStepThrough()&gt; Private Sub InitializeComponent()
  
      End Sub
      Protected WithEvents lbldata As System.Web.UI.WebControls.Label
  
      Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
          'CODEGEN: This method call is required by the Web Form Designer
          'Do not modify it using the code editor.
          InitializeComponent()
      End Sub
  
  #End Region
  
  
      Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Handles MyBase.Load
          'Put user code to initialize the page here
          ServerPath = common.ReadResourceFileaddress(ServerPath)
          If Not IsPostBack Then
  
              'Dim ServerPath As String = Server.MapPath("ReportViewer")
  
  
              Dim objAdmin As New Admin()
              Dim allCloumn As New DataSet
              allCloumn = objAdmin.GetAllColumsFromDB()
              FillTemplate()
  
              If allCloumn Is Nothing Then
                  gridDiv.Visible = False
                  gridDiv1.Visible = False
                  btnShowGrid.Enabled = False
                  btnCancel.Enabled = False
                  lblError.Text = common.ReadResourceValue(ServerPath, "ReportrelatedTableisnotpresentinDataBase")
                  Exit Sub
              End If
  
              chkFields.DataSource = allCloumn
              chkFields.DataBind()
              Session.Add("myDataGrid", gridData)
              'chkFields.Items(0).Enabled = False
              'chkFields.Items(0).Selected = True
  
              Dim intVal As Integer = chkFields.Items.Count
              'For a = 0 To intVal - 1
              '    chkFields.Items(a).Selected = True
              'Next  
              Session("DynamicResultReportGridData") = Nothing
          End If
  
          Dim ds As New DataSet
          ds = Session("DynamicResultReportGridData")
          If Not ds Is Nothing Then
              DefineGridStructure(Session("DynamicResultReportGridData"))
              gridData.DataBind()
              gridDiv.Visible = True
              gridDiv1.Visible = True
              btnShowGrid.Enabled = True
              btnCancel.Enabled = True
          Else
              gridDiv.Visible = False
              gridDiv1.Visible = False
              'btnShowGrid.Enabled = False
              'btnCancel.Enabled = False
              'lblError.Text = "Report related Table is not present in DataBase."
          End If
  
  
  
          lblDisplayHeader.Text = common.ReadResourceValue(ServerPath, "CustomizeTestCaseResultReport") 'common.ReadResourceValue(ServerPath, "TestCaseResultReport")
  
      End Sub
  
  
      Protected Sub btnShowGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowGrid.Click
  
          Try
              Dim objAdmin As New Admin()
              Dim allCloumnData As New DataSet
              gridDiv.Visible = False
              gridDiv1.Visible = False
              allCloumnData = objAdmin.GetAllDataFromTestCaseResult()
              Dim intVal As Integer = chkFields.Items.Count
              If allCloumnData Is Nothing Then
                  lblError.Text = common.ReadResourceValue(ServerPath, "ReportrelatedTableisnotpresentinDataBase") &amp; common.ReadResourceValue(ServerPath, "PleaseAddColumnsfirst")
                  Exit Sub
              Else
                  lblError.Text = ""
              End If
              For a = intVal - 1 To 0 Step -1
                  If Not chkFields.Items(a).Selected Then
                      allCloumnData.Tables(0).Columns.RemoveAt(a)
                  End If
              Next
  
              If Not allCloumnData.Tables(0).Columns.Count &gt; 0 Then
                  lblError.Text = common.ReadResourceValue(ServerPath, "Pleaseselecttherequiredcolumnstogeneratethereport")
                  Exit Sub
              Else
                  lblError.Text = ""
              End If
  
              'INSERT Identity column
              Dim dc As New DataColumn("ID_Data")
              dc.AutoIncrement = True
              dc.AutoIncrementSeed = 1
              dc.AutoIncrementStep = 1
              allCloumnData.Tables(0).Columns.Add(dc)
  
              'Set values for existing rows
              For i As Integer = 0 To allCloumnData.Tables(0).Rows.Count - 1
                  allCloumnData.Tables(0).Rows(i).Item("ID_Data") = i + 1
              Next
  
  
              gridDiv.Visible = True
              gridDiv1.Visible = True
              DefineGridStructure(allCloumnData)
              gridData.DataBind()
  
          Catch ex As Exception
              lblError.Text = "Error : " &amp; ex.Message.ToString()
          End Try
  
      End Sub
      Protected Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
  
          Response.Redirect(Request.RawUrl)
      End Sub
  
  
  
  
      Protected Sub btnEmailReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmailReport.Click
          gridDiv.Visible = True
          gridData.Visible = True
          flag = True
          Dim data As New DataSet
          data = Session("DynamicResultReportGridData")
          DefineGridStructure(data)
          gridData.Rebind()
  
          gridData.ExportSettings.Excel.Format = GridExcelExportFormat.Biff
          gridData.ExportSettings.IgnorePaging = True
          gridData.ExportSettings.ExportOnlyData = False
          gridData.ExportSettings.OpenInNewWindow = True
  
          gridData.MasterTableView.ExportToExcel()
  
      End Sub
  
  
      Protected Sub grid_GridExporting(ByVal source As Object, ByVal e As GridExportingArgs)
          If flag Then
              'Dim filename As String = "TestCaseResultReport.xls"
              Dim strDateTime As String = Date.Now.ToString()
              strDateTime = strDateTime.Replace("/", "")
              strDateTime = strDateTime.Replace(" ", "_")
              strDateTime = strDateTime.Replace(":", "-")
              Dim filename As String = "TestCaseResultReport_" &amp; strDateTime &amp; ".xls"
              Dim path As String = Server.MapPath("~/PDFReport/") + filename
              Using fs As FileStream = File.Create(path)
                  Dim info As [Byte]() = System.Text.Encoding.[Default].GetBytes(e.ExportOutput)
                  fs.Write(info, 0, info.Length)
              End Using
  
              Response.Redirect("EmailReport.aspx?docID=" &amp; filename &amp; "&amp;ids=dy")
          End If
      End Sub
  
  
  
  
      Private Function Company_Excel() As String
          Return ""
      End Function
  
  
      Protected Sub btnEPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEPDF.Click
          'gridDiv.Visible = True
          'gridData.Visible = True
  
          Dim data As New DataSet
          data = Session("DynamicResultReportGridData")
          'DefineGridStructure(data)
  
          ''grid.ExportSettings.Pdf.AllowPrinting = True
          'gridData.ExportSettings.Pdf.PaperSize = GridPaperSize.Letter
          'gridData.ExportSettings.Pdf.PageWidth = 1500
          ''grid.ExportSettings.Pdf.PageTitle = "Users"
          ''grid.ExportSettings.Pdf.AllowModify = True
          ''grid.ExportSettings.Pdf.AllowCopy = True
  
          'gridData.ExportSettings.Pdf.FontType = Telerik.Web.Apoc.Render.Pdf.FontType.Embed
  
          'gridData.ExportSettings.IgnorePaging = True
          'gridData.ExportSettings.ExportOnlyData = False
          'gridData.ExportSettings.OpenInNewWindow = True
  
          'ApplyStyleSheetExportPDF(gridData.MasterTableView)
          'gridData.MasterTableView.ExportToPdf()
  
          Dim General As New TestMagic.General()
          Try
              Dim objDefectManagement_ExportToPDF As New DefectManagement_ExportToPDF()
              objDefectManagement_ExportToPDF.ProjectName = Convert.ToString(Session("Project"))
              'objDefectManagement_ExportToPDF.SubProjectName = Convert.ToString(Session("SubProject"))
              ' objDefectManagement_ExportToPDF.StartDate = Convert.ToDateTime(ViewState("StartDate")).ToString("MM/dd/yyyy")
              ' objDefectManagement_ExportToPDF.EndDate = Convert.ToDateTime(ViewState("EndDate")).ToString("MM/dd/yyyy")
  
  
              Dim pdfName As String = objDefectManagement_ExportToPDF.ExportToPDF_ManageDefects(True, data.Tables(0), "CustomizeTestCaseResultReport")
          Catch ex As Exception
              rowlblError.Visible = True
              lblError.Text = General.ReadResourceValue(ServerPath, "GeneralexceptionoccurredwhileretrievingPDFReport")
          End Try
  
  
      End Sub
  
  
  
      Protected Sub btnExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExcel.Click
          gridDiv.Visible = True
          gridData.Visible = True
  
          Dim data As New DataSet
          data = Session("DynamicResultReportGridData")
          DefineGridStructure(data)
          gridData.Rebind()
          gridData.ExportSettings.Excel.Format = GridExcelExportFormat.Biff
  
          gridData.ExportSettings.IgnorePaging = True
          gridData.ExportSettings.ExportOnlyData = False
          gridData.ExportSettings.OpenInNewWindow = True
  
          For Each item As GridNoRecordsItem In gridData.MasterTableView.GetItems(GridItemType.NoRecordsItem)
              item.Display = False
          Next
  
          gridData.MasterTableView.ExportToExcel()
      End Sub
      Protected Sub btnECSV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnECSV.Click
          gridDiv.Visible = True
          gridData.Visible = True
  
          Dim data As New DataSet
          data = Session("DynamicResultReportGridData")
          DefineGridStructure(data)
          gridData.Rebind()
          gridData.ExportSettings.IgnorePaging = True
          gridData.ExportSettings.ExportOnlyData = False
          gridData.ExportSettings.OpenInNewWindow = True
          gridData.MasterTableView.ExportToCSV()
      End Sub
  
      Private Sub DefineGridStructure(ByVal allCloumnData As DataSet)
  
          'Dim grid As New RadGrid()
  
          gridData.DataSource = allCloumnData
          Session.Add("DynamicResultReportGridData", allCloumnData)
          gridData.Skin = "Default"
          gridData.Width = Unit.Percentage(100)
          gridData.PageSize = 15
          gridData.AllowPaging = True
          gridData.AllowFilteringByColumn = True
          gridData.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
          gridData.AutoGenerateColumns = False
  
          'Add Customers table
          gridData.MasterTableView.Width = Unit.Percentage(100)
  
          If gridData.MasterTableView.Columns.Count &gt; 0 Then
              For a = gridData.MasterTableView.Columns.Count - 1 To 0 Step -1
                  gridData.MasterTableView.Columns.RemoveAt(a)
              Next
  
          End If
  
          gridData.MasterTableView.DataKeyNames = New String() {"ID_Data"}
  
          Dim intVal As Integer = allCloumnData.Tables(0).Columns.Count
          For a = 0 To intVal - 2
              Dim boundColumn As New GridBoundColumn()
  
              boundColumn.DataField = allCloumnData.Tables(0).Columns(a).Caption().Trim().ToString()
              boundColumn.HeaderText = allCloumnData.Tables(0).Columns(a).Caption().Trim().ToString()
              boundColumn.UniqueName = allCloumnData.Tables(0).Columns(a).Caption().Trim().ToString()
              boundColumn.ItemStyle.CssClass = "text2"
  
              boundColumn.HeaderStyle.CssClass = "GridHeader"
              boundColumn.AllowFiltering = True
              gridData.MasterTableView.Columns.Add(boundColumn)
          Next
  
  
      End Sub
  
      Protected Sub grid_NeedDataSource(ByVal Source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gridData.NeedDataSource
  
          gridDiv.Visible = True
          gridDiv1.Visible = True
          gridData.Visible = True
          Dim allCloumnData As DataSet = Session("DynamicResultReportGridData")
          gridData.DataSource = allCloumnData
  
      End Sub
  
      'To Save Tempate Details
      Protected Sub btnSaveTemplate_Click(sender As Object, e As EventArgs) Handles btnSaveTemplate.Click
          Dim objAdmin As New TestMagic.Admin()
          Dim dsData As New DataSet
          Dim columnName As String = ""
          Dim result As Boolean
          Dim isTemplate As Boolean
          gridDiv.Visible = False
          gridDiv1.Visible = False
  
  
          Dim myArray As New ArrayList()
          For Each item As ListItem In chkFields.Items
              If item.Selected = True Then
                  myArray.Add(item)
                  columnName = String.Concat(columnName, "|", item.Value)
              End If
          Next
  
          If Trim(txtTemp.Text).Length = 0 Then 'check template name should not blank
              lblMsg.Text = common.ReadResourceValue(ServerPath, "Pleaseentertemplatename")
  
          ElseIf myArray.count = 0 Then 'check column name should not unchecked
  
              lblMsg.Text = common.ReadResourceValue(ServerPath, "Pleaseselectcolumnname")
          Else
  
              Try
                  dsData = objAdmin.ShowColumns(cboTemplate.SelectedValue, HttpContext.Current.Session("Project"))
  
                  If dsData.Tables(0).Rows.Count &gt; 0 Then
  
                      'Update Template Details
                      result = objAdmin.UpdateTemplate(cboTemplate.SelectedValue, columnName, HttpContext.Current.Session("Project"))
  
                      If result Then
                          lblMsg.Text = common.ReadResourceValue(ServerPath, "Templateupdatedsuccessfully")
                      End If
  
                  Else
  
                      'Check Template Name Already Exist or Not
                      isTemplate = objAdmin.IsTemplateExist(txtTemp.Text.Trim, HttpContext.Current.Session("Project"))
  
                      If isTemplate Then
  
                          lblMsg.Text = common.ReadResourceValue(ServerPath, "Thistemplatenameisalreadyexist")
  
                      Else
                          'Save Template Details
                          result = objAdmin.AddTemplate(txtTemp.Text.Trim, columnName, HttpContext.Current.Session("Project"))
  
                          If result Then
                              lblMsg.Text = common.ReadResourceValue(ServerPath, "Templatesavedsuccessfully")
  
                              FillTemplate()
                              cboTemplate.SelectedIndex = cboTemplate.Items.IndexOf(cboTemplate.Items.FindByText(txtTemp.Text.Trim))
  
                          End If
  
                      End If
  
                  End If
              Catch ex As Exception
  
              End Try
  
          End If
  
  
      End Sub
  
  
      Private Sub FillTemplate()
          Dim objAdmin As New Admin()
          cboTemplate.Items.Clear()
          cboTemplate.DataSource = objAdmin.ShowTemplate(HttpContext.Current.Session("Project"))
          cboTemplate.DataTextField = "TemplateName"
          cboTemplate.DataValueField = "Id"
          cboTemplate.DataBind()
          cboTemplate.Items.Insert(0, New ListItem("&lt;New Template&gt;", 0))
          cboTemplate.SelectedIndex = 0
      End Sub
  
      Protected Sub cboTemplate_SelectedIndexChanged(sender As Object, e As EventArgs)
          Dim objAdmin As New TestMagic.Admin()
          Dim dsData As New DataSet
          Dim allCloumn As New DataSet
          gridDiv.Visible = False
          gridDiv1.Visible = False
  
          lblMsg.Text = " "
  
          'Get columns by Template &amp; Project
          dsData = objAdmin.ShowColumns(cboTemplate.SelectedValue, HttpContext.Current.Session("Project"))
  
          For Each item As ListItem In chkFields.Items
              item.Selected = False
          Next
  
          If cboTemplate.SelectedValue &lt;&gt; 0 Then
  
              ViewState("columnsName") = dsData.Tables(0).Rows(0).Item("ColumnsName").ToString()
  
              Dim columnsName As String = ViewState("columnsName")
              Dim columns As String() = columnsName.Split("|")
  
              Dim column As String
              For Each column In columns
                  For Each item As ListItem In chkFields.Items
                      If column = item.Value Then
                          item.Selected = True
                      End If
                  Next
              Next
  
  
              'For Each item As ListItem In chkFields.Items
              '    If columnsName.Contains(item.Value) Then
              '        item.Selected = True
              '    End If
              'Next
  
              txtTemp.Text = cboTemplate.SelectedItem.Text
              txtTemp.Enabled = False
  
          Else
  
              txtTemp.Text = " "
              txtTemp.Enabled = True
  
              For Each item As ListItem In chkFields.Items
                  item.Selected = False
              Next
  
          End If
  
      End Sub
  
  End Class
  </code></pre>
  
  <p>Filter TextBox value disappear after postback telerik:RadGrid
  Thanks in advance.</p>