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?
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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.