Developing an asp.net page with a master page that utilizes a content page (web control). The web control consists of 4 elements: PickListType dropdown, UserPickList (not important), Organization label, Body label, and Address dropdown.
Upon changing the picklisttype dropdown, I aim to hide the Body and Address, and vice versa. Initially, the functionality works, but on subsequent attempts, it fails to locate the ids of Body and Address (visibility set to hidden) during the second change. Upon inspecting the source code, it appears that either the Ids have changed or the elements have disappeared entirely during postback.
Struggling to resolve this issue. Any suggestions?
function DropDownChange() {
var picklist = document.getElementById("PickListTypeList");
var usercontainer = document.getElementById("ctl00_ctl00_ctl00_PageContentPlaceHolder_PageContentPlaceHolder_paneDetails_ApplicerPickListContainer");
var orgcontainer = document.getElementById("ctl00_ctl00_ctl00_PageContentPlaceHolder__C_OrganizationPickListContainer");
var addresslabel = document.getElementById("LegalBodyAddressLabel");
var addressbox = document.getElementById("ctl00_ctl00_ctl00_PageContentPlaceHolder_PageContentPlaceHolder_paneDetails_ApplicantsRadDock_C_ApplicantsControl_AddEditApplicantDock_C_AddApplicantDock_C_LegalBodyAddressComboBox");
if(picklist.value.toLowerCase() === "sometext"){
usercontainer.style.display = "none";
orgcontainer.style.display = "inline";
addresslabel.visibility = "visible";
addressbox.style.display = "inline";
}
else{
usercontainer.style.display = "inline";
orgcontainer.style.display = "none";
addresslabel.visibility = "hidden";
addressbox.style.visiblity = "none";
}
}
Currently using .ClientId for dynamic id retrieval, considering switching to static ids without success in targeting Address and Label. Attempting to access these elements from the parent (master) page by traversing into the control (controlname.nameofelementID.ClientID).