Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8028715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:12:28+00:00 2026-06-05T00:12:28+00:00

Why Is the following code producing error of Object reference not set to an

  • 0

Why Is the following code producing error of “Object reference not set to an instance of an object Even when i am using the set session method inboth of the button click events?

public partial class MergePopUp : System.Web.UI.Page
{

List<MergeAccounts> Mlist = new List<MergeAccounts>();

protected void Page_Load(object sender, EventArgs e)
{

}
private void SetSession()
{
    if (Session["Account"] == null)
    {
        Session["Account"] = Mlist;
    }
}


protected void AddToMergeList_Click(object sender, EventArgs e)
{
    MergeAccounts obj = new MergeAccounts();
    obj.AccountNumber = Convert.ToInt32(AccountNumber.Text);
    obj.PinNumber = Convert.ToInt32(PinNumber.Text);
    int temp = obj.IsAccNoValid(obj.AccountNumber, obj.PinNumber);
    if (temp == 0)
    {
        FoundOrNot.Visible = true;
        FoundOrNot.Text = "Enter a valid Pin Number against this Account number";
    }
    else
    {
        DataSet MyDataSet = obj.ShowDetails(obj.AccountNumber, obj.PinNumber);
        foreach (DataRow myRow in MyDataSet.Tables[0].Rows)
        {
            AccountTitle.Text = myRow["Title"].ToString();
            Balance.Text = myRow["Balance"].ToString();
            CreationDate.Text = myRow["CreationDate"].ToString();
        }
        obj.AccountTitle = AccountTitle.Text;
        obj.Balance = Convert.ToDouble(Balance.Text);
        obj.CreationDate = Convert.ToDateTime(CreationDate.Text);
        Mlist.Add(obj);
        Session["Account"] = Mlist;
        SetSession();
    }
}
protected void AddNext_Click(object sender, EventArgs e)
{
    foreach (TextBox i in this.Page.Form.Controls.OfType<TextBox>().ToList())
    {
        i.Text = null;
    }
    FoundOrNot.Visible = false;
}
protected void CheckList_Click(object sender, EventArgs e)
{
    SetSession();
    Response.Redirect("Merge.spx");
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:12:29+00:00Added an answer on June 5, 2026 at 12:12 am

    are the two buttons on the same page? If so, create a method accessible to both buttons where the session variable is set. Make sure you check if it’s already set so that it’s only set once.

    private void SetSession()
    {
       if(Session["Account"] == null)
          Session["Account"] = "Value";
       else
          //what do you want to do here
    }
    
    
    protected void button1_click(.....)
    {
        SetSession();
        //do something
    }
    
    protected void button2_click(....)
    {
        SetSession();
        //redirect
    }
    

    by this your session is always set whether first button or second button is clicked

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code doesn't compile ( error CS0123: No overload for 'System.Convert.ToString(object)' matches delegate
The following code is producing an Unsupported operator types error: $data = $modelData +
I have narrowed down my error to following set of codes producing different behaviour
I am using the following code to display a cutom 404 not found with
We have code that is producing the following unhandled exception: Error Message: System.Reflection.TargetParameterCountException: Parameter
I'm trying to implement a simple LinkedList The following code, producing this error: error:
I have the following code which is producing this error. I cannot understand why
The following code is producing the error I stated in the title: $authkey =
The following code continues to be displayed even if there are entries in my
The following code is generating an error on the variable con2 saying non-static variable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.