Last post Oct 23, 2020 11:20 PM by mgebhard
Oct 23, 2020 11:06 PM|kafsar|LINK
Error Object reference not set to an instance of an object with the following code: c#
bool AppPhotoChk = (bool)reader1["enroll"];
if (AppPhotoChk == true)
AppEnroll.Checked = true // here is error throw (Object reference not set to an instance of an object)
Same error on: AppEnroll.Checked = (reader.GetBoolean(reader.GetOrdinal("enroll")));
Can Please someone help!
Oct 23, 2020 11:20 PM|mgebhard|LINK
The checkbox shown in your code snippet is an HTML input NOT a server control. You cannot access the checkbox input as if it is a Server control. Use the following syntax to access the value.
Secondly, only checked HTML checkbox values are submitted by the browser. You'll need to handle null.
Lastly, you should always use standard framework constructs. In this case, the ASP.NET CheckBox control. You can also add runat="server" to the HTML input which will allow you to access the input by Id in the code behind.