Web Hosting Talk







View Full Version : C#/ASP .NET Web app Object Reference Error. HELP Please!


MBlock
08-28-2007, 10:56 AM
I need some help troubleshooting this error message I am getting. First some real fast background. I am developing a web application that has an ASP.NET front end with C# code behind and a SQL database interface on the backend. That being said first some information about the ASP label in question:

In my HTML I have a table with categories and databound elements. I need one of the category labels in one row to change dynamically dependent upon a value set in a radio button list. That value is stored in another database. First here is the HTML for the table:

<TABLE cellSpacing="1" cellPadding="2" width="98%" bgColor="#000000" border="0">
<TR>
<TD bgColor="#000066" colSpan="2"><SPAN class="Table">Funds Distribution</SPAN></TD>
</TR>

<TR>
<TD align="left" bgColor="#ffffff">
<asp:Label ID="TESTTEST" CssClass="text" Visible="True" Runat="server">BLAH</asp:Label>

<asp:Label id="lblDebitView" CssClass="text" Visible="False" Runat="server">Debit Card</asp:Label>

<asp:Label id="lblCashView" CssClass="text" Visible="False" Runat="server">Cash</asp:Label>

<asp:Label id="lblCheckView" CssClass="text" Visible="False" Runat="server">Check</asp:Label> </TD>

<TD align="right" bgcolor="#ffffff">
<span class="text"><%# DataBinder.Eval(Container.DataItem, "DistroDesc") %> </span>
<span class="text"><%# DataBinder.Eval(Container.DataItem, "fundsAmnt") %> </span>
</TD>
</TR>
<TR>
<TD align="center" bgcolor="#ffffff" colSpan="2"><SPAN Class="text"><B>Credible Wireless Note Date:<B><%# DataBinder.Eval(Container.DataItem, "CW Date") %> </SPAN></TD></TR>
</TABLE>


Then I have the following definition in my C# code:

protected System.Web.UI.WebControls.Label TESTTEST;

and there are respective definitions for the other ASP labels written exactly the same, just with the respective variable name instead of TESTTEST.

Finally, depending on the state of the aforementioned radio button I want to either make visible or hide those asp:labels above. The test was just a test but of the other three only one can be visible at a time. All I am calling in the C# code is this:

this.TESTTEST.Visible = true;

Again, respective for all other variables.

And I get the following error message on ALL of the asp:labels (i.e. when one threw the error I commented it out and then it hit the next one ect.)

The error message:
Object reference not set to an instance of an object.

The error source:
clients2.0

The error stack trace:
at clients2._0.Financial.client_budgetForm.getUpdateInformation(Boolean isFuture) in \\devmachine\wwwroot$\project\financial\budgetform.aspx.cs:line 691
at clients2._0.Financial.budgetForm.checkFutureBudgets() in \\devmachine\wwwroot$\project\financial\budgetform.aspx.cs:line 422
at clients2._0.Financial.budgetForm.Page_Load(Object sender, EventArgs e) in \\devmachine\wwwroot$\project\financial\budgetform.aspx.cs:line 384


exec usp_C0609View



Last comment is line 691 of budgetform.aspx.cs is:

this.TESTTEST.Visible = true;

Line 422 of budgetform.aspx.cs. is just a FunctionY call to FunctionX of which inside is where line 691 is.

Line 384 is a function call to the FunctionY


PLEASE ANY help you may have or advice on where I can start looking to troubleshoot this would be great! I have been banging my head for hours trying to figure this out. I am hoping I am just overlooking something small and easy as I am a relative rookie in this flavor of programming. Thanks!

Steve_Arm
08-28-2007, 11:02 AM
I understand that you want to do it on PostBack.
Either you call each label's visible property OR you can wrap them in a asp:Panel
and use it's visible property.
If you don't want to do it on Postback you'll have to use javascript.

However I see that the error has nothing to do with the labels.

Have yo added the controls manually or fro mthe toolbar?

MBlock
08-28-2007, 11:08 AM
However I see that the error has nothing to do with the labels.

Have yo added the controls manually or fro mthe toolbar?



I added the controls manually through the HTML code listed above. Also, I was assuming the error had to do with the labels since the line of code listed in the stack trace I posted is the line of code where I try to access the labels visible property. Furthermore, if I comment out that line than the program will run just fine otherwise.

I am going to re-read your other suggestions and try to see if I comprehend them enough to give it a shot.

EDIT: Just for possible clarification if needed. This table is one of a few all inside of an asp: panel used as a page on the site. Not sure if that helps grasp the scenerio or not.

Steve_Arm
08-28-2007, 11:16 AM
If the definitions - protected System.Web.UI.WebControls.Label TESTTEST; - exist then your code will compile without failure, as it is now I assume.
If the control in the HTML is not declared if I'm not mistaken it compiles fine but gives an error when you use it. Might want to check for syntaax errors on your declarations.

MBlock
08-28-2007, 11:21 AM
If the control in the HTML is not declared if I'm not mistaken it compiles fine but gives an error when you use it. Might want to check for syntaax errors on your declarations.

Ok, I see what you're saying. I did have to write the definitions myself in the code the "Protected System.Web.UI.WebControls.Label TESTTEST;

Where should the control in the HTML be declared? Because this has all the symptoms of that being the problem as it does compile just fine and then throws the object reference error saying it's not set to an instance of an object. Leading me to believe that I was missing a declaration somewhere but I am unfamiliar with where else I need a declaration. As it stands I just have the <asp:label> line of code and then the protected declaration in the code behind.

Azavia
08-29-2007, 10:33 PM
What version of .NET are you running?