JS List
asked on
asp.net vb response.writefile NullReferenceException: Object reference not set to an instance of an object.
Hello,
I'm using response.writefile("thisfi le.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("la bel1"), 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
I'm using response.writefile("thisfi
"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("la
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You need a recursive FindControl function. Have a look at the answer of this question: https://www.experts-exchange.com/questions/24994181/How-to-get-reference-to-nested-listview-using-findcontrol-method.html
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Create usercontrols for the individual pages
Create main report that calls all the data once and uses the usercontrol pages as needed.
ASKER