0

这是控制结构

ContentPlaceHolder
  --> 向导
      --> 面板

我正在使用 setTimeout 在 x 分钟后显示面板。

如何获取面板的 ClientID?

所需的 javascript 行类似于:

setTimeout(displayExtendSession('<%= ExtendSession.ClientID  %>', 600000);

aspx

<asp:Content ID="Content1" runat="server" ...>
    <asp:Wizard ID="wizard1" runat="server" ... >
        <asp:Panel ID="ExtendSession" runat="server">
            <asp:Label ID="ExtendSessionLifePrompt" runat="server" Text="Your session is going to expire in 1 minute. Would you like to extend your Session?"></asp:Label>
            <asp:Button ID="ExtendSessionLife" runat="server" Text="Yes" />
            <input type="button" id="CancelExtendSessionLife" value="No" onclick="HideExtendSession('<%= ExtendSession.ClientID %>'); return false;" />  
        </asp:Panel>
    </asp:Wizard>
</asp:Content>

javascript

function HideExtendSession(msgBox) {
    if (msgBox)
        document.getElementById(msgBox).style.display = "none";
}
function DisplayExtendSession(msgBox) {
    if (msgBox) 
        document.getElementById(msgBox).style.display = "block";
}

setTimeout(DisplayExtendSession('<%= ExtendSession.ClientID  %>', 600000);
setTimeout(HideExtendSession('<%= ExtendSession.ClientID %>', 720000);
4

3 回答 3

1

要获得ExtendSession我认为您需要做的是:

setTimeout(displayExtendSession('<%= wizard1.FindControl("ExtendSession").ClientID  %>', 600000);

更新

如果您无法进入wizard1,那么也许是这样:

setTimeout(displayExtendSession('<%= Content1.FindControl("wizard1").FindControl("ExtendSession").ClientID  %>', 600000);

我希望双引号没问题,但我相信如果这没有帮助,你可以切换它们。

于 2010-10-27T16:01:08.943 回答
0

如果你对性能不太感兴趣,

以下代码可能是轻松完成任务的一种方法。

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(FindRecursiveControl(this,"ExtendSessionLife").ClientID.ToString());
}

Control FindRecursiveControl(Control cd, string Name)
{
    if (cd.ID == Name && cd.ID !=null)
        return cd;

    foreach (Control c in cd.Controls)
    {
        Control cfind = FindRecursiveControl(c, Name);

        if (cfind != null)
            return cfind;
    }

    return null;
}
于 2010-12-05T06:17:14.840 回答
0

如果你添加

ClientIDMode="Static"

<asp:Panel ID="ExtendSession" runat="server">

导致

<asp:Panel ID="ExtendSession" ClientIDMode="Static" runat="server">

asp.net 不会破坏您面板的 id 和

document.getelementbyid("ExtendSession")

将返回由 asp:panel 控件呈现的 <div> 的 id。

于 2010-10-27T16:09:25.167 回答