title: How to implement a search bar on master page ASP.NET
body: <p>I am trying to create a search bar for my ASP.NET pages that will be included in the master so it will be shown on all pages. Entering search text and hitting search will send you to results.aspx, which then retrieves the value of the text from the master page search box and displays data from the database in a grid view. Searching from my home page works fine, but I want the user to be able to enter a new search text while on the results page and have the page reload with the new data in the grid view. 
  Here is the code on results.aspx page load</p>
  
  <pre><code>   if (PreviousPage != null)
              {
                  TextBox SourceTextBox =
                      (TextBox)PreviousPage.Master.FindControl("txtSearchMaster");
                  if (SourceTextBox != null)
                  {
                      txtSearch.Text = SourceTextBox.Text;
                  }
              }
  </code></pre>
  
  <p>Code on master page</p>
  
  <pre><code>    &lt;div id="search"&gt;
           &lt;asp:HyperLink ID="linkAddFile" runat="server" BorderStyle="None" NavigateUrl="~/Default.aspx" Width="150px" &gt;Add File&lt;/asp:HyperLink&gt;
           &lt;asp:TextBox ID="txtSearchMaster" runat="server"&gt;&lt;/asp:TextBox&gt;
           &lt;asp:Button ID="btnSearch" runat="server" Text="Search" PostBackUrl="~/results.aspx" /&gt;
       &lt;/div&gt;
  </code></pre>
  
  <p>The issue is once I get to the results page and try to do a new search from there, my conditional (PreviousPage != null) says that it <em>is</em> null. </p>