Solved

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

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now