Link to home
Start Free TrialLog in
Avatar of JS List
JS ListFlag for United States of America

asked on

asp.net vb response.writefile NullReferenceException: Object reference not set to an instance of an object.

Hello,
I'm using response.writefile("thisfile.inc") on an .aspx web page.  
"thisfile.inc" contains a table and a bunch of labels like this: <asp:Label ID="label1" runat="server" Text="" />
On page load, after I've retrieved the data, I'm trying to put text in those labels.

Coming up with error:
Object reference not set to an instance of an object.
NullReferenceException: Object reference not set to an instance of an object.

Here the code behind
Dim lbl1 As Label
lbl1 = DirectCast(FindControl("label1"), Label)
lbl1.Text = Row("xNames").ToString

I'm creating several reports that the some of the same pages.  
Each report has a big long SQL string call that pulls data from 7 different tables.  All the reports don't need the same data.

Instead of duplicating coding to create the common pages on the report, I'm trying to include them.  
This way I can pull 1 set of data with 1 call and not several for each report.
I tried creating usercontrols but the same problem happens.

I read someplace where you can't use findcontrol on a label.  Is this true?  Is there an alternative?

Is there a better way to do this?

Jess
Avatar of JS List
JS List
Flag of United States of America image

ASKER

Thanks Scott
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JS List

ASKER

Based on Kaufed's answer - I found another solution to the problem.  
Create usercontrols for the individual pages
Create main report that calls all the data once and uses the usercontrol pages as needed.