0

我正在尝试将母版页添加到现有页面以创建站点范围的标题。不幸的是,当我将母版页引用添加到 Default.aspx 时,一些 Javascript 大小控件停止工作

function ChangePanelHeight(){
    var MyPanel;
    var NewHeight=(screen.height*.45);
    MyPanel = document.getElementById('pnlContainer');
    MyPanel.style.height = NewHeight + "px";
}

当我添加母版页时,该 javascript 函数(嵌入在内容页面上)起作用,但调整大小不起作用。换句话说,alert('Hey!');在 javascript 中触发就好了,但由于某种原因,面板高度保持不变。没有它它工作正常。母版页如下所示:

<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site.master.vb"  Inherits="PropertyManagementSystem.Site" %>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div id="header">
    <table>
    <tr>
        <td><h1>Property Management System</h1></td>
    </tr>
    <tr>
        <td><h2>All Your Property - Managed At The Palm Of Your Hand</h2></td>
        <td><h2>Welcome <asp:Label ID="lblWhoName" runat="server"/></h2></td>
    </tr>
    <tr>
        <td><a id="lHome" href="Default.aspx">Home</a></td>
        <td><a id="lManageDevices" href="ManageDevices.aspx">Manage Devices</a></td>
        <td><a id="lManageLookupTables" href="ManageLookups.aspx">Manage Lookups</a></td>
        <td><a id="lHelp" href="Help.aspx">Help</a></td>
        </tr>
    </table>
    </div>
    <div>
        <asp:ContentPlaceHolder ID="MainContent" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>
4

1 回答 1

0

试试这个(使 .getElementID 的元素 ID 引用控件的客户端 ID):

function ChangePanelHeight(){
    var MyPanel;
    var NewHeight=(screen.height*.45);
    MyPanel = document.getElementById('<%=pnlContainer.ClientID %>');
    MyPanel.style.height = NewHeight + "px";
}
于 2013-08-02T13:22:24.353 回答