Can someone help with this response.text?

  • Thread starter Thread starter TN Bella
  • Start date Start date
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.
 
How about this:

litResponse.text +="<b>Account Number</b>: " & CType(("txtAcctNum" &
index),TextBox).text & "<br>"
 
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?
 
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.
 
Back
Top