Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i stored session on dropdownchange(DropDownList1_SelectedIndexChanged) event in asp.net.

and submit time i use this session but on submit time it's throwing error instance not set .

i check many time it's work mostly perfectly . ex. if i run project and out of 10 time it's work 9 time perfectly and 1 time it's instance not set.

can i use hidden variable in instead of session . and what is hidden variable life ?

What I have tried:

C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
 var announcementData = JsonConvert.DeserializeObject<AnnouncementDataList>(json.ToString());
                Session["announcementData"] = null;
                Session["announcementData"] = announcementData;
        }


//on sendnow i requried session but clear some time or not set 

  protected void SendNow_Click(object sender, EventArgs e)
        {
 var selectedNews = apiresult.Items[apiresult.SelectedIndex].Text;
                    NewsDataList newsData = new NewsDataList();
                    if ((NewsDataList)Session["newsApiResponse"] != null)
                    {
                        newsData = (NewsDataList)Session["newsApiResponse"];
                        noti.newsdata = newsData.data.Where(x => x.Headline == selectedNews).FirstOrDefault();
                    }
}
Posted
Updated 11-Oct-17 19:50pm
v2
Comments
Karthik_Mahalingam 12-Oct-17 1:13am    
in submit you are using different key for the session.

1 solution

Um. Look at your code:
C#
Session["announcementData"] = announcementData;

C#
if ((NewsDataList)Session["newsApiResponse"] != null)
{
    newsData = (NewsDataList)Session["newsApiResponse"];
If you use different keys, you get different data...

Try:
C#
if ((NewsDataList)Session["announcementData"] != null)
{
    newsData = (NewsDataList)Session["announcementData"];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900