asp.net頁面中Menu控制項下拉式功能表被frame擋住和iframe自適應高度的解決辦法

來源:互聯網
上載者:User
     當你在做一個仿windows程式的頂部菜單架構的時候,在asp.net中你可能會使用兩個frame,一個frame在上面用來放菜單一個frame在下面用來方菜單點擊後開啟的頁面.頁面實現很簡單,單啟動並執行時候你就發現放菜單的那個frame將菜單的下列菜單在擋住根本伸不到下面的frame中.解決被擋住的問題是不能使用frame,做法是在一個單獨的asp.net頁面中放一個menu 和一個iframe,嗯,至此下拉式功能表不會被擋住,單又有一個新問題出來了,那就是iframe的高度問題,如果強制寫死它的高度,那根本是不可接受的.如果解決?解決的辦法就是使用javascript 在body的onload和onsized事件中對iframe的高度進行控制.下面代碼解決上述的問題.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>

<html>
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>無標題頁</title>

    <script language="javascript" type="text/javascript">

function aaaaa()
{

  document.getElementById('f1').height=document.body.clientHeight-80;
}

    </script>

</head>
<body onload="aaaaa()" onresize="aaaaa()" scroll="no" style="margin: 0">
    <form id="form1" runat="server">
    <table>
        <tr>
            <td height="80">
                <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal" BackColor="#E3EAEB"
                    DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#666666"
                    StaticSubMenuIndent="10px">
                    <StaticSelectedStyle BackColor="#1C5E55" />
                    <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                    <DynamicHoverStyle BackColor="#666666" ForeColor="White" />
                    <DynamicMenuStyle BackColor="#E3EAEB" />
                    <DynamicSelectedStyle BackColor="#1C5E55" />
                    <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                    <StaticHoverStyle BackColor="#666666" ForeColor="White" />
                    <Items>
                        <asp:MenuItem Text="建立項1" Value="建立項1">
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項">
                                <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            </asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                            <asp:MenuItem Text="建立項" Value="建立項"></asp:MenuItem>
                        </asp:MenuItem>
                        <asp:MenuItem Text="建立項2" Value="建立項2"></asp:MenuItem>
                        <asp:MenuItem Text="建立項3" Value="建立項3"></asp:MenuItem>
                    </Items>
                </asp:Menu>
            </td>
        </tr>
    </table>
    <iframe id="f1" scrolling="auto" width="100%" height="200" src="HTMLPage5.htm"></iframe>
    </form>
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.