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

时间:2011-11-08 09:36:24

标签: javascript asp.net

我有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);

它设置为html div tag.above代码工作正常。当我通过aspx.cs页面发送它显示contentplace holder元素和高度未设置。

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

但是在两个进度面板中都放置了竞争对手。 我该怎么做aspx.cs页面

1 个答案:

答案 0 :(得分:0)

您正在混合元素和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);
}