Thursday, 15 July 2010

javascript - getElementById doesn't find element after setting visibility to hidden -


I am working on an asp.net page, and I have a master page that uses content pages (My web control). In my web control, I have 4 elements when I type picklist type drop down

picklist type - dropdown user pixelist - important organization - label body - label address - drop down

when I I change the picklist type dropdown, then I want to hide the body and know, and vice versa

When I change it for the first time, it works, but for the second time, it says that it is physical and Address (I hide Sets their visibility) can not find the ID for the second time. Looking through the source, it seems that in these elements 1) during the postback, their ID has been changed. And ClintID can not get them or 2) they disappear.

I do not seem to understand how to do it. any idea? Change function dropdown () {var picklist = document.getElementById ("PickListTypeList"); Var user container = 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 () === "some time ago") {usercontainer.style.display = "none"; Orgcontainer.style.display = "inline"; Addresslabel.visibility = "visible"; Addressbox.style.display = "inline"; } Other {usercontainer.style.display = "inline"; Orgcontainer.style.display = "none"; Addresslabel.visibility = "hidden"; Addressbox.style.visiblity = "none"; }}

This is the source: I have to find IDA dynamically. I used to, but then I changed it to static (the same id every single time) and I still can not find the address and label I am going to control these elements under the Guardian (master) page (controlname .nameofelementID.ClientID).

2 thoughts / options

  • Use Add Class, and then use document.getElementsByClassName to retrieve them. .NET will not change classes on HTML tags after a postback.

    OR

    • Wrap them in the ID / display, and then the document. GetElementById to the wrapping tag, Access the code> firstchild . I would recommend not to runat = "server" for this code

No comments:

Post a Comment