title: Passing form data from masterpage to other pages ASP.NET
body: <p>I have asked a similar question before, but I didn't have a firm grasp on what the problem I was encountering was.  My problem is I cannot get the data from a TextBox residing on the master when the page changes.  Here is what happens:</p>
  
  <ol>
  <li>MasterPage with TextBox and Button.</li>
  <li>Data is entered into the TextBox and Button is clicked.</li>
  <li>Form's action is set to search.aspx, webapp navigates there.</li>
  <li>This function gets the TextBox's content:</li>
  </ol>
  
  <hr>
  
  <pre><code>Public Function oSearchString(ByVal oTextBoxName As String) As String  
      If Master IsNot Nothing Then  
          Dim txtBoxSrc As New TextBox  
          txtBoxSrc = CType(Master.FindControl(oTextBoxName), TextBox)  
          If txtBoxSrc IsNot Nothing Then  
              Return txtBoxSrc.Text  
          End If  
      End If  
      Return Nothing  
  End Function
  </code></pre>
  
  <p>When this code executes, it returns <code>""</code>, even though there is text entered into the box.  I tried putting a default value into the box, and that gets passed through just fine (i.e. <code>&lt;asp:TextBox ID="searchbox" runat="server" text="searchbox"&gt;&lt;/asp:TextBox&gt;</code> yields <code>"searchbox"</code>).</p>
  
  <p>Now that I have submitted the search form from the home page, I am on the search page (search.aspx).  If I enter the search string again, the code returns whatever I put into the textbox.  I tried modifying the code above from <strong><code>Master</code></strong> to <strong><code>PreviousPage</code></strong> but that did not work at all since the textbox control resides on the Master page.</p>
  
  <p>Hopefully I laid out the background information well enough, let me know if further clarification is required.</p>
  
  <hr>
  
  <p><strong>EDIT</strong>:  Using <code>Request.Form("searchbox")</code> yields <code>Nothing</code>.  I inspected the <code>Request.Form()</code> object and found that my textbox's ID is actually <code>ctl00$searchbox</code>.  Using that as the ID or its Index (3 in this case) gives me the proper result.  Would it be best to rewrite the function to check all the keys in <code>Request.Form()</code> for keys containing <code>searchbox</code>, or is there a way I can get the actual ID of the textbox?  For the former option, this is what I came up with:</p>
  
  <pre><code>Public Function oSearchString(ByVal oTextBoxName As String) As String
      For Each oKey As String In Request.Form.AllKeys
          If oKey.Contains(oTextBoxName) Then
              Return Request.Form(oKey)
          End If
      Next
      Return ""
  End Function
  </code></pre>