views:

36

answers:

2

This is the control structure

ContentPlaceHolder
  --> Wizard
      --> Panel

I am using setTimeout to display the panel after x minutes.

How do I get the ClientID of the panel?

The line of javascript needed is something like:

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);
A: 

To get the client Id of ExtendSession I think what you need to do is:

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

updated

if you can't get to wizard1, then maybe this:

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

I would expect the double quotes to be fine, but I'm sure you can switch them around if that's not helping.

ilivewithian
I get an error stating wizard1 is not declared. Btw, I think you should also use the double quotes outside the expression and single quotes inside.
mjw06d
A: 

If you add

ClientIDMode="Static"

to

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

resulting in

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

asp.net will not mangle your panel's id and

document.getelementbyid("ExtendSession")

will return the id of the <div> rendered by the asp:panel control.

bnieland
Unfortunately, I am not running asp.net 4 so I can't leverage the use of ClientIDMode
mjw06d