使用javascript获取母版页中嵌套面板控件的clientID
这是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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要获取
ExtendSession
的客户端 ID,我认为您需要做的是:更新
如果您无法访问 Wizard1,那么也许是这样:
我希望使用双引号没关系,但我相信如果这没有帮助,你可以改变它们。
To get the client Id of
ExtendSession
I think what you need to do is:updated
if you can't get to wizard1, then maybe this:
I would expect the double quotes to be fine, but I'm sure you can switch them around if that's not helping.
如果您添加
到
asp.net中
,则不会破坏您的面板的 id,并且
会返回
If you add
to
resulting in
asp.net will not mangle your panel's id and
will return the id of the <div> rendered by the asp:panel control.
如果您不太关心性能等,
以下代码可能是轻松完成任务的一种方法。
If you are not much into performance and all,
Following code might be one way to easily achieve the tasks.