Solved

C#.NET class available in some methods but not in others

Posted on 2013-11-29
5
377 Views
Last Modified: 2013-12-16
Here is the codebehind:

public partial class ViewDetailedActivity : System.Web.UI.Page
    {
        public AstraFunctions vdaa = new AstraFunctions();
        public AstraFunctions vdaabdt = new AstraFunctions();
        public AstraFunctions vdaabdc = new AstraFunctions();
        protected void Page_Load(object sender, EventArgs e)
        {
                if (!IsPostBack)
                {
                    AstraHdr.Set_Title("View Detailed ASTRA Activity");
                    SetVDAAPanelView(); // <----  THIS WORKS!
                }
        }
/*.............*/
        protected void SetVDAAPanelView()
        {
            try
            {
//THIS ALL WORKS
                string sSqlCommand = "Astra_ReportActivity";
                SqlParameter[] SQLParameters = null;
                vdaa.SetUp(gvViewDetailedASTRAActivity, sSqlCommand, SQLParameters);
                vdaa.SetDataSet();
                Response.Write(vdaa.gv.ID.ToString();
                pnlViewDetailedASTRAActivity.Visible = true;
                pnlViewDetailedASTRAActivityByDate.Visible = false;
                pnlViewDetailedASTRAActivityByDODACC.Visible = false;
            }
            catch (Exception ex)
            {
                Response.Write("Error in SetVDAAPanelView():  " + ex);
            }
        }
/*..............*/
        protected void gvViewDetailedASTRAActivity_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            try
            {
                vdaa.gv.ID.ToString(); // DOES NOT work!
                //vdaa.gv_PageIndexChanging(sender, e); // this DOES NOT work!
            }
            catch (Exception ex)
            {
                Response.Write("Error in gvViewUnprocessedReceipts_PageIndexChanging():  " + ex);
            }
        }

Open in new window


When I trigger gvViewDetailedASTRAActivity_PageIndexChanging I get the following error:


Error in gvViewDetailedASTRAActivity_PageIndexChanging(): System.NullReferenceException: Object reference not set to an instance of an object. at VIM.ASTRA.ViewDetailedASTRAActivity.gvViewDetailedASTRAActivity_PageIndexChanging(Object sender, GridViewPageEventArgs e) at [filename]: line [linenumber]

I can access the class object in SetVDAAPanelView() but not gvViewDetailedASTRAActivity_PageIndexChanging(object sender, GridViewPageEventArgs e) -- what gives?

Any help would be wonderful!
Thanks!
0
Comment
Question by:EchoBinary
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 39686111
Without knowing what the AstraFunctions() class is doing it is difficult to say, but you could try setting the gridview object value in the method.

            try
            {
                gridview vdaa.gv = (gridview)gvViewDetailedASTRAActivity;
                vdaa.gv.ID.ToString(); // DOES NOT work!
                //vdaa.gv_PageIndexChanging(sender, e); // this DOES NOT work!
            }
0
 

Author Comment

by:EchoBinary
ID: 39686129
It seems to me from experimenting that the vdaa object itself is what is not an instance of an object.
0
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 39686158
I am assuming that  vdaa.SetUp assigns values to the vdaa object. In the original page load, it is not being ran unless you are doing that somewhere else as well. If the gridview pageIndexChanging is performing a postBack, the value is not being set. Put a breakpoint in the page load event on line 11- SetVDAAPanelView(); // <----  THIS WORKS! and see if it hits when the pageIndexChanging is fired.
0
 

Author Comment

by:EchoBinary
ID: 39690043
I came up with an answer kinda on my own - it was to load the objects into the session in Page_Load() like so:

vdaa = Session["vdaa"] != null ? (AstraFunctions)Session["vdaa"] : new AstraFunctions();

Open in new window


then I just load them back from session elsewhere.
0
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 500 total points
ID: 39690599
I would change the not Postback or add the vdaa.SetDataSet() to else clause. Setting this variable in a session variable will drastically increase your viewState size.

You can set it that way, but there are some security concerns with session variables. You should read through this page.

http://msdn.microsoft.com/en-us/library/ms178581.ASPX
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question