Can someone help with this response.text?

Discussion in 'ASP .Net' started by TN Bella, Jul 13, 2004.

  1. TN Bella

    TN Bella Guest

    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.
     
    TN Bella, Jul 13, 2004
    #1
    1. Advertisements

  2. 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......
     
    Craig Deelsnyder, Jul 13, 2004
    #2
    1. Advertisements

  3. TN Bella

    TN Bella Guest

    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
     
    TN Bella, Jul 14, 2004
    #3
  4. 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)
     
    Craig Deelsnyder, Jul 14, 2004
    #4
  5. TN Bella

    TN Bella Guest

    thank you!!
     
    TN Bella, Jul 15, 2004
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.