-2

i am getting NullReferenceException at

"tb = Page.FindControl("table1").FindControl("txtAccount" +i) as TextBox;"  

can anyone help me this code has done in c# CRM2013.

if (accountEntity.Attributes.Contains("telephone1"))
   {
      string phone = accountEntity.Attributes["telephone1"].ToString();

      tb = Page.FindControl("table1").FindControl("txtAccount" +i) as TextBox;
              if (tb!= null)
              {
                  tb.Text = phone;
              }

    }
Pranav
  • 8,563
  • 4
  • 26
  • 42
  • Which object is `null`? Does `Page.FindControl("table1")` actually find anything? Your code assumes it does, but if it doesn't then that's the exception you would get. – David Sep 11 '14 at 13:37
  • 4
    It's likely not finding a control named "tabel1" – Jesper Fyhr Knudsen Sep 11 '14 at 13:38
  • I believe that a remark is due about how bad an idea it is to shove ASPX pages inside CRM (primary reason: it's not supported and bound to randomly break anytime the platform is upgraded) – Alex Sep 11 '14 at 13:55

1 Answers1

1

Your NullReferenceException isn't related to CRM. You are getting this error because this expression is returning null

Page.FindControl("table1") 

So make sure you have an element on your page with the id table1.

Sachin
  • 40,216
  • 7
  • 90
  • 102