I have the following:
ctrlSearch.ascx
<asp:Button CssClass="button-search" ID="imgSearch" runat="server"
PostBackUrl="~/Secure/SearchResults.aspx" Font-Bold="True" />
-----------------------------------------------------------------
<%@ Page Title="Search Results" Language="C#" MasterPageFile="~/MasterPages/OneColumn.master" AutoEventWireup="true"
CodeBehind="SearchResults.aspx.cs" Inherits="OmegaLove.Web.UI.Pages.SearchResults" %>
<%@ Reference VirtualPath="~/Controls/Search/ctrlSearch.ascx" %>
in the behind code of searchresults.aspx
if ((Page.PreviousPage != null) && Page.PreviousPage.IsCrossPagePostBack)
{
UserControl ucSearch = PreviousPage.FindControl("ctrlSearch") as UserControl;
DropDownList ddlAge1 = new DropDownList();
ddlAge1 = (DropDownList) ucSearch.FindControl("search_age_start");
lblSentFromPreviousPage.Text = ddlAge1.SelectedValue;
}
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 33: UserControl ucSearch = PreviousPage.FindControl("ctrlSearch") as UserControl;
Line 34: DropDownList ddlAge1 = new DropDownList();
Line 35: ddlAge1 = (DropDownList) ucSearch.FindControl("search_age_start");
Line 36: lblSentFromPreviousPage.Text = ddlAge1.SelectedValue;
Line 37: }