问题描述
我的页面上有一个更新面板。此更新面板有一个计时器。计时器启动后,我希望将整个页面置于更新面板之外,变成灰色且不可编辑。下面是带有计时器的“更新”面板的代码:
<asp:ScriptManager ID="ScriptManager1" runat="server" ></asp:ScriptManager>
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="1000" />
<asp:UpdatePanel ID="securityQuestPanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
<ContentTemplate>
<div class="sticky"> <span style="border:2px; color:red;font-size:25px;" >Time Remaining: <asp:Label ID="Label1" runat="server"></asp:Label></span> <br />
</div>
</ContentTemplate>
</asp:UpdatePanel>
我在更新面板之外有很多代码。无论采用哪种方式,我都可以使代码背景变成灰色且不可编辑。我无法在现有更新面板的内容模板内移动该代码。我创建了一个小样本来说明我的意思:
下面是aspx页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="SendBulkEmail.WebForm4" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="src1" runat="server"></asp:ScriptManager>
<div>
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="1000" />
<asp:UpdatePanel ID="StockPricePanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
<ContentTemplate>
<div class="sticky"> <span style="border:2px; color:red;font-size:25px;" >Time Remaining:
<asp:Label ID="Label1" runat="server"></asp:Label></span> <br />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div> <asp:Button ID="btnTest" runat="server" Text="Test" OnClick="test_click" /></div>
</form>
</body>
</html>
下面是我的.cs页面代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SendBulkEmail
{
public partial class WebForm4 : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
if (!IsPostBack)
{
if (Session["CountdownTimer"] == null)
{
Session["CountdownTimer"] = new TimeSpan(0,1,0);
}
TimeSpan current = (TimeSpan)Session["CountdownTimer"];
Label1.Text = current.ToString("%m") + " minutes and " + current.ToString("%s") + " seconds";
}
}
protected void Timer1_Tick(object sender,EventArgs e)
{
TimeSpan ts2sec = new TimeSpan(0,2); // 2 seconds
TimeSpan ts = (TimeSpan)Session["CountdownTimer"]; // current remaining time from Session
TimeSpan current = ts - ts2sec; // Subtract 5 seconds
Label1.Text = current.ToString("%m") + " minutes and " + current.ToString("%s") + " seconds";
Session["CountdownTimer"] = current; // put new remaining time in Session
if (current.TotalMilliseconds <= 0)
{
Session["CountdownTimer"] = "";
Timer1.Enabled = false;
Label1.Text = "Your Session is timed out. ";
btnTest.Visible = false;
}
}
protected void test_click(object sender,EventArgs e)
{
string a = "This is Test";
}
}
}
我想在计时器启动时使btnTest不可见。我无法在现有更新面板内移动btnTest。这只是我需要的一个可行示例。
我们将不胜感激任何帮助。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)