如何在aspx.cs页面设置document.getElementById(progressPanel.ID)

How to set document.getElementById(progressPanel.ID) in aspx.cs page

本文关键字:getElementById progressPanel ID document 页面设置 aspx cs      更新时间:2023-09-26

我有javascript设置面板的位置和javascript在

function ShowProgressPanel(progresspanel)
{
    var progressPanelId = document.getElementById(progressPanel.ID);
    alert(progressPanelId);
    if (progressPanelId != null) 
    {
        var height = Math.min(document.documentElement.clientHeight, document.body.offsetHeight);
        alert(height);
        var width = Math.min(document.documentElement.clientWidth, document.body.offsetWidth);
        var xPos = Math.round((width / 2) - (progressPanelId.clientWidth / 2));
        var yPos = Math.round((height / 2) - (progressPanelId.clientHeight / 2));
        setLocation(progressPanelId, { x: xPos, y: yPos });
    }
    function setLocation(element, point) 
    {
        Sys.UI.DomElement.setLocation(element, point.x, point.y);
    }
}

我正在从aspx页面传递客户端id

var progressPanel = document.getElementById('<%=_progressPanel.ClientID %>');
ShowProgressPanel(progressPanel);

设置为HTMLdiv标签。以上代码运行良好。当我通过aspx.cs页面发送时,它显示contentplace holder元素和高度未设置。

string script = string.Format(@"ShowProgressPanel('{0}');", _progressPanel.ClientID);
ScriptManager.RegisterStartupScript(this, typeof(Page), _progressPanel.ID, script, true);

但是在这两个进度面板中都放置在contentplaceholder中。如何在aspx.cs页面

你把元素和id混在一起了。

function ShowProgressPanel(progresspanelId)
{
    var progressPanelElement = document.getElementById(progresspanelId);
    setLocation(progressPanelElement , { x: xPos, y: yPos });
}
function setLocation(element, point) 
{
    Sys.UI.DomElement.setLocation(element, point.x, point.y);
}