I have two User Controls namely:
- ucGILocation.ascx (UC1)
- UcUpdateReportDescriptionSection.ascx (UC2)
which both are loaded in an .aspx page named NewReport.aspx
I want to hide some controls from UC2 when a dropDownList from UC1 selected index == 3.
However, it gives me a NullException error when I hide the controls in UC2 whenever the dropdownlist's index selected == 3.
I believe it is caused by the page_load because whenever the dropdown list selectedIndexChanged occurs, it will post-back the whole NewReport.aspx and since the page_load is not finish, it is already trying to hide the controls from UC2 .
Here is my code:
UC1 (code behind)
protected void ddlGIUpdatePillar_SelectedIndexChanged(object sender, System.EventArgs e) //akmal adds to hide div_locationItems when "Cyber Security" is selected { if (ddlGIUpdatePillar.SelectedIndex == 3)//checking if "Cyber Security" is selected { div_locationItems.Visible = false; UcUpdateReportDescriptionSection pnl_toHideDescItems2 = (UcUpdateReportDescriptionSection)Page.FindControl("panel_hideDescItems2"); pnl_toHideDescItems2.Visible = false; } }
the third line
pnl_toHideDescItems1.Visible = false;
is not executed since it throws NullReference exception. Is there any other alternatives that I can do to make it work.