Click here to Skip to main content
15,905,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I'm getting an "Object reference not set to an instance of an object" in the following code (inside Page_Init):
C#
DynaControlsBLL objDyn = new DynaControlsBLL();
HtmlGenericControl dynDiv = new HtmlGenericControl();
//this line m getting error..
objDyn.GenerateTabControls("FS_TaxiMenu", out dynDiv, out gListDynamicControls, true, false, false);
phDynamic.Controls.Add(dynDiv); 
Session["gListDynamicControls"] = gListDynamicControls;
Does anyone have any ideas what the problem could be.
Posted
Updated 3-May-12 23:44pm
v4
Comments
Mohammad A Rahman 4-May-12 5:24am    
It is really hard to understand what is happening out there by looks of line of code and little description. Please describe bit more.
ythisbug 4-May-12 5:33am    
DynaControlsBLL objDyn = new DynaControlsBLL(); HtmlGenericControl dynDiv = new HtmlGenericControl(); objDyn.GenerateTabControls("FS_TaxiMenu", out dynDiv, out gListDynamicControls, true, false, false); phDynamic.Controls.Add(dynDiv); Session["gListDynamicControls"] = gListDynamicControls;

this is dat code in pageinit
Mohammad A Rahman 4-May-12 5:47am    
From the code what I can see, GenerateTabControls method takes 6 parameters, out of 6 dynDiv has been instantiated where is gListDynamicControls coming from?
And please show us the details about the exception program throws....
ythisbug 4-May-12 5:51am    
List<dynacontrolspl> gListDynamicControls = new List<dynacontrolspl>();
this is the class to retrieve dynamictable column details..
Mohammad A Rahman 4-May-12 5:56am    
As Solution 2 suggested, please debug the code. If you have difficulties to find where is the exception coming from try using try..catch block to identify the method where is the exception raised from :)

I think you'll find that the line you think you are getting the error on is not actually where the error is:
C#
objDyn.GenerateTabControls("FS_TaxiMenu", out dynDiv, out gListDynamicControls, true, false, false); 
I rather suspect that the error is inside the method GenerateTabControls. If you put a breakpoint on this code and step into this method, you should be able to identify the line that is really throwing the exception.
 
Share this answer
 
Comments
ythisbug 4-May-12 5:57am    
i put breakpoint and in gListDynamicControls am getting count is 2
and dynDiv is null
Pete O'Hanlon 4-May-12 6:01am    
Actually step into the method. You need to see what's going on in GenerateTabControls as that's where your error is coming from. This method is returning you a null dynDiv which you attempt to add as a control, so there's something going wrong in there.
ythisbug 4-May-12 6:12am    
ok thanks hanlon
Check that you used new key word to create objDyn onject
C#
classname objDyn = new objDyn();
 
Share this answer
 
Comments
ythisbug 4-May-12 5:33am    
your talking about this code
DynaControlsBLL objDyn = new DynaControlsBLL();
HtmlGenericControl dynDiv = new HtmlGenericControl();
objDyn.GenerateTabControls("FS_TaxiMenu", out dynDiv, out gListDynamicControls, true, false, false);
phDynamic.Controls.Add(dynDiv);
Session["gListDynamicControls"] = gListDynamicControls;

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