Error when reading value

Nov 18, 2010 at 11:22 AM
Edited Nov 18, 2010 at 11:24 AM

Password Field Type

When I try to access the field value I get the following error: Object reference not set to an instance of an object.
I can access other field values and the field name is correct.

Code:
string value = spListItem["UserPassword"].ToString();

Oct 24, 2011 at 9:52 AM

me too. i tried to debug and found that it's always return null when it hit this line of statement.

Please see the red highlighted color.  How to resolve it?

PasswordFieldControl.cs

  protected override void CreateChildControls()        {           

// load the control template before attempting to assign values to controls           

base.CreateChildControls();
            PasswordField pwdField = this.Field as PasswordField;
            if (pwdField != null)            {               

switch (this.ControlMode)                {                   

// obtain reference to presentation control and initialize values used on display forms                   

case SPControlMode.Display:                       

this.DisplayLabel = this.TemplateContainer.FindControl(CTRL_LBL_ID) as Label;                     

  if (this.DisplayLabel != null)                        {                       

    this.DisplayLabel.Text = this.ItemFieldValue as string;                        }         

              break;
                    // obtain reference to presentation control and initialize values used on edit and new forms                 

  default:                       

this.PasswordTextBox = this.TemplateContainer.FindControl(CTRL_TXT_ID) as TextBox;