Load text in Array and display on other webpage

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asmx126453
    New Member
    • Sep 2008
    • 72

    Load text in Array and display on other webpage

    Hey Guys i need help with this last thing i cant get to work

    The error i get with it is:
    NullReferenceEx ception was unhandled by user code

    Object reference not set to an instance of an object.

    Code:
            #region adding textfields from database 
            public void Filling_Textfields(string[] OfferteArray, bool nieuw)
            {
                txtNoteID.Text = txtNoteID.Text;
                txtBTW.Text = "19";
                txtOfferteNr.Text = txtOfferteNr.Text;
                txtDatum.Text = Functions.DateToNL(txtDatum.Text);
                txtDebNr.Text = txtDebNr.Text;
                txtKlantNaam.Text = OfferteArray[4];
                txtContactpersoon.Text = txtContactpersoon.Text;
                txtOmschrijving.Text = txtOmschrijving.Text;
                txtOrderNr.Text = txtOrderNr.Text;
    Now i get an error on the rule: txtKlantNaam.Te xt = OfferteArray[4];

    what i whanne get done is that it loads some values from my previos page to this 1
    The only thing that he loads in the page now is 19 from the BTW

    it first worked with the OfferteArray but now something is wrong but i dont now what if yuo have onther way how i can load some values from the previos page in this one i am all ear
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    In txtKlantNaam.Te xt = OfferteArray[4];, either txtKlantNaam is null or the array OfferteArray itself is null. You can find out which one it is by a simple if test.

    Comment

    • asmx126453
      New Member
      • Sep 2008
      • 72

      #3
      Okey i cheked if it whas null like this

      Code:
          txtNoteID.Text = txtNoteID.Text;
                  if (txtNoteID.Text == null)
                  {
                      txtBTW.Text = "20";
                  }
      and now BTW is not being fild in so it looks like the txtbox is not null if i am right

      i cudent use the code OfferteArray becase than i get an error before he executes the code
      Last edited by asmx126453; Nov 12 '08, 11:01 AM. Reason: [code] tag

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Don't test the Text property for null. Test the objects themselves for null, i.e the text boxes or labels themselves.

        Comment

        • asmx126453
          New Member
          • Sep 2008
          • 72

          #5
          Srry but i dont realy understand what you mean cud you give some more information about what to do

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            if you do if(xtNoteID.Tex t == null) you are checking if xtNoteID's Text is null or not. if you do if(xtNoteID == null), you are testing if xtNoteID itself is null or not. The null reference exception is caused by dereferencing an object which is null(i.e using . on an object which is null). In your code, you never called dot on the Text, you called dot (.) on the xtNoteID itself (e.g in xtNoteID.Text). So you need to test whether xtNoteID is null or not. Don't forget to check the array also.

            Comment

            • asmx126453
              New Member
              • Sep 2008
              • 72

              #7
              Well i did i like that way now when i check my txtbox it is not null

              but my OfferteArray i cant check becase i get the error again what i have posted here i just dont now wy it wont work becase i have more codes like that and and that 1 i dont get an error

              Code:
                          if (nieuw == false)
                          {
                              txtReferentieNr.Text = OfferteArray[8];
                              txtSubTotaal.Text = OfferteArray[9].Replace(",", ".");
                              txtBTW.Text = OfferteArray[11];
              at these i dont get an error but there is no differene in the code

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                To check if the array itself is null or not, then you can use if(OfferteArray == null).

                P.S This really should be starting to be clear to you by now.

                Comment

                • asmx126453
                  New Member
                  • Sep 2008
                  • 72

                  #9
                  Yep i know but i am not an expert yet and about the error

                  OfferteArray is null your right

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #10
                    Originally posted by asmx126453
                    Yep i know but i am not an expert yet and about the error

                    OfferteArray is null your right
                    Just so you know, NullReferenceEx ceptions occur when you attempt to use an Object that is null (hasn't been instantiated yet).

                    Comment

                    • asmx126453
                      New Member
                      • Sep 2008
                      • 72

                      #11
                      hey

                      i dont realy now what you mean with instantiated ??

                      i am from holland and i dont realy now what you mean with that can u give me some more information on it

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        object o;
                        The reference o has been created but it is pointing to nothing (null).
                        o = new object();
                        Now the reference is pointing to an object which has been instantiated (created/initialized).
                        Better read a C# tutorial/textbook.

                        Comment

                        Working...