3

aspx ページに asp:Content タグを追加しました。

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

そして、私は以下のようなjavascriptを持っています、

   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 = '';
                }

expandAll または collapseall をクリックすると、対応する Div を展開して折りたたむ必要があります。しかし、コンテンツ プレース ホルダーがページに追加されるため、フィールド名の前に付けられ、私の JavaScript は機能しません。展開の折りたたみが機能するように、この JavaScript でどのような変更を行う必要がありますか。

私のフィールド名は、MainContent_divOut、MainContent_divQOR のようになります...「MainContent_」を接頭辞として変数 ID を変更する必要があります。ただし、最初のフィールド「divOut」を除いて、それでも機能しませんでした。

4

2 に答える 2

5

You can fix that in the web.config depending on your asp.net version, if you are using 4.0, you can set it inline , <asp:TextBox runat="server" ClientIDMode="static" id="txt1" />

this will prevent the prefix to be added to your control id.

more detail here

于 2012-05-18T18:07:16.670 に答える
1

<%=Element.ClientID%>たとえば、次のように使用します。<%=divOut.ClientID%>ページ上の任意のサーバー側コントロールのクライアント ID を取得するために使用します。

于 2012-05-18T18:33:21.303 に答える