Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

how to pass dropdownlist from one page to another?

$
0
0

i can't seem to figure out how to use a SESSION variable to store/retrieve/set the value of a dropdown list when a user switches pages.

on the ASPX page, i have:

<asp:DropDownList ID="ddl_ProjectList" runat="server" AutoPostBack="True" DataSourceID="sql_ProjectList" DataTextField="project" DataValueField="project_key" EnableViewState="true" OnSelectedIndexChanged="ddl_ProjectList_SelectedIndexChanged"></asp:DropDownList>

and on the ASPX.CS page, i have:

protected void ddl_ProjectList_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList SourceDropDownList = (DropDownList)Page.FindControl("ddl_ProjectList");
System.Web.HttpContext.Current.Session["project"] = SourceDropDownList.SelectedValue.ToString();
}

then... when i run the app and change the dropdownlist, i get the following:

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 15:     {
Line 16:         DropDownList SourceDropDownList = (DropDownList)Page.FindControl("ddl_ProjectList");
Line 17:         System.Web.HttpContext.Current.Session["project"] = SourceDropDownList.SelectedValue.ToString();
Line 18:     }
Line 19: }


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>