Can someone help with this response.text?

T

TN Bella

Hello,
I don't know why I keep getting this error. I have 15 of each txtacctnum
(txtacctnum - txtacctnum14), txtcostcntr, txtrefnum, and txtacctamt.
Some of the inputs are null, so I don't want to display unless there is
a value. Can someone please help?

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Here is my code:

Dim index as Integer
For index=0 To 14

litResponse.text +="<b>Account Number</b>: " &
CType(Me.FindControl("txtAcctNum" & index.ToString()), TextBox).text &
"<br>"
litResponse.text +="<b>Cost Center</b>: " &
CType(Me.FindControl("txtCostCntr" & index.ToString()), TextBox).text &
"<br>"
litResponse.text +="<b>Account Number</b>: " &
CType(Me.FindControl("txtRefNum" & index.ToString()), TextBox).text &
"<br>"
litResponse.text +="<b>Account Number</b>: " &
CType(Me.FindControl("txtActAmt" & index.ToString()), TextBox).text &
"<br>"
Next

Thank you.
 
S

Scott M.

How about this:

litResponse.text +="<b>Account Number</b>: " & CType(("txtAcctNum" &
index),TextBox).text & "<br>"
 
J

John Saunders

TN Bella said:
Hello,
I don't know why I keep getting this error. I have 15 of each txtacctnum
(txtacctnum - txtacctnum14), txtcostcntr, txtrefnum, and txtacctamt.
Some of the inputs are null, so I don't want to display unless there is
a value. Can someone please help?

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Here is my code:

Dim index as Integer
For index=0 To 14

litResponse.text +="<b>Account Number</b>: " &
CType(Me.FindControl("txtAcctNum" & index.ToString()), TextBox).text &
"<br>"

There is no txtAcctNum0, is there?
 
T

TN Bella

no....I did change it For index = 1 To 14 but all I get is null values,
none of the textboxes that have a value are being displayed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top