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.
 
C

Craig Deelsnyder

TN 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>"
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.

sounds like one of your controls is not being found, so the FindControl
is null, causing the .Text to throw a null pointer (see your
stacktrace). Are you sure all of these controls are there, and all have
the correct names? I noticed you said txtacctnum - txtacctnum14, not
txtacctnum0 - txtacctnum14 as that first one must have 0 at the end of
it's name......
 
T

TN Bella

Right now it says:
For index = 1 To 14

The first textbox is txtAcctNum...following txtAcctNum1,
txtAcctNum2...txtAcctNum14.

How do I get that first textbox to be displayed w/o changing the
name...? It can't be 0 to 14, because that didn't work before.

Thanks for the help
 
C

Craig Deelsnyder

TN said:
Right now it says:
For index = 1 To 14

The first textbox is txtAcctNum...following txtAcctNum1,
txtAcctNum2...txtAcctNum14.

How do I get that first textbox to be displayed w/o changing the
name...? It can't be 0 to 14, because that didn't work before.

Thanks for the help

Just check if it's 0

Dim index as Integer
Dim indexAsString as String
For index=0 To 14
If index>0 then
indexAsString = index.ToString()
Else
indexAsString = String.Empty
End If

litResponse.text +="<b>Account Number</b>: " &
CType(Me.FindControl("txtAcctNum" & indexAsString)
 

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

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top