0

I have a textbox used to search for products. This textbox is placed in the site's masterpage. However, I'm getting a null error for the frmSearch value once posted back.

masterpage search:

<asp:TextBox ID="frmSearch" runat="server" CssClass="searchbox"></asp:TextBox>
<asp:LinkButton ID="searchGo" CssClass="searchbutton" PostBackUrl="search.aspx"  runat="server">GO</asp:LinkButton>

search.aspx pageload:

if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
        {
            Page previousPage = PreviousPage;
            TextBox tbSearch = (TextBox)PreviousPage.FindControl("frmSearch");
            searchValue.Text = for tbSearch.Text;
        }

Where am I going wrong?

ComfortablyNumb
  • 1,448
  • 10
  • 37
  • 64

1 Answers1

3

frmSearch doesn't exist on your PreviousPage. It exists on the Master page of PreviousPage.

If you change the following line to include .Master, it should pull that text box.

TextBox tbSearch = (TextBox)PreviousPage.Master.FindControl("frmSearch");
Doozer Blake
  • 7,677
  • 2
  • 29
  • 40