ComfortablyNumb
ComfortablyNumb

Reputation: 1456

Cross Postback from Masterpage

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?

Upvotes: 0

Views: 1728

Answers (1)

Doozer Blake
Doozer Blake

Reputation: 7797

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");

Upvotes: 3

Related Questions