Solved

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

Posted on 2013-11-29
5
384 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 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