0
當我嘗試保存配置文件時,我得到的對象引用未設置爲對象錯誤的實例。C# - 保存配置文件ASP.NET給出'對象引用未設置'錯誤
我嘗試添加一個「如果」 聲明 如果(this.Profile.ProfileDetail!= NULL) 但它仍然給了我同樣的錯誤。
這是我的代碼:
private void SaveProfile()
{
this.Profile.ProfileDetail.FullName = txtfname.Text;
this.Profile.ProfileDetail.IdentityCardNo = txtcardno.Text;
this.Profile.ProfileDetail.IdentityCardColour = ddlcardcolor.SelectedValue;
this.Profile.ProfileDetail.IdentityCardExpiryDate = DateTime.Parse(txtcardexp.Text);
this.Profile.ProfileDetail.Race = ddlrace.SelectedValue;
this.Profile.ProfileDetail.Religion = ddlreligion.SelectedValue;
this.Profile.ProfileDetail.ContactInformation.Address1 = txtaddress1.Text;
this.Profile.ProfileDetail.ContactInformation.Address2 = txtaddress2.Text;
this.Profile.ProfileDetail.ContactInformation.Address3 = txtaddress3.Text;
this.Profile.ProfileDetail.ContactInformation.Postcode = txtpostcode.Text;
this.Profile.ProfileDetail.ContactInformation.District = ddldistrict.SelectedValue;
this.Profile.ProfileDetail.ContactInformation.OfficePhone = txtphoneoffice.Text;
this.Profile.ProfileDetail.ContactInformation.HomePhone = txtphonehome.Text;
this.Profile.ProfileDetail.ContactInformation.MobilePhone = txtphonecell.Text;
this.Profile.ProfileDetail.ContactInformation.Email = txtemail.Text;
//this.Profile.ProfileDetail.FirstName = txtFirstName.Text;
//this.Profile.ProfileDetail.LastName = txtLastName.Text;
//this.Profile.ProfileDetail.IdentityCardNo = txtICNo.Text;
//this.Profile.ProfileDetail.DateOfBirth = DateTime.Parse(txtDateOfBirth.Text);
//this.Profile.ProfileDetail.Gender = (Gender)Enum.Parse(typeof(Gender), ddlGender.SelectedValue, true);
//this.Profile.Preferences.TimeZone = ddlTimeZones.SelectedValue;
//this.Profile.Preferences.Culture = ddlCultures.SelectedValue;
this.Profile.Save();
this.ResetElements();
}
'this.Profile'可能爲空,在這種情況下'this.Profile'是什麼?你是登錄到應用程序還是你的班級的這個屬性?或當前上下文的配置文件? – Damith
@Damith個人資料爲空。我點擊編輯填寫信息,但我無法保存。 – Belzelga
@Damith謝謝。它現在工作正常。我添加了如果這個配置文件在東西之上是空的。謝謝:'D – Belzelga