ContentPlaceHolderID added as a prefix to my form fields

I have an asp: content tag added to my aspx page.

<asp:Content ID="Step1Content" ContentPlaceHolderID="MainContent" Runat="Server">

and I have javascript as shown below

   function switchAllMenu() {
            var ids = new Array('divOut', 'divQOR', 'divPop', 'divRD', 'divCst', 'divRep', 'divCnt');
            var i, el, newObj, el1;
            if (document.getElementById('aSwitchAllMenu').value == "Expand All") {
                document.getElementById('aSwitchAllMenu').value = "Collapse All";
                for (i = 0; i < ids.length; i++) {
                    el = document.getElementById(ids[i]);
                    newObj = ids[i].replace("div", "li");
                    el1 = document.getElementById(newObj);
                    el.style.display = '';
                    el1.className = 'active';
                }
            }
            else {
                document.getElementById('aSwitchAllMenu').value = "Expand All";
                for (i = 0; i < ids.length; i++) {
                    el = document.getElementById(ids[i]);
                    newObj = ids[i].replace("div", "li");
                    el1 = document.getElementById(newObj);
                    el.style.display = 'none';
                    el1.className = '';
                }

when I click the expandAll or collapseall button, the corresponding Div should expand and collapse. But since the owner of the content place is added to the page, it prefixes the field names, and my JavaScript does not work. what change should i make in this javascript so that my camber works.

My field names look like this: MainContent_divOut, MainContent_divQOR ... should I use var id with the prefix "MainContent_". However, even this did not work expet for the 1st "divOut" field.

+3
source share
2 answers

web.config asp.net, 4.0, , <asp:TextBox runat="server" ClientIDMode="static" id="txt1" />

.

+5

<%=Element.ClientID%> . <%=divOut.ClientID%>, .

+1

All Articles