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="s开发者_如何学编程earchGo" 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?
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");
精彩评论