我在我的网页上有一个传递消息的函数。该函数将标签更改为消息,但在3秒后,我希望标签隐藏或分配了一个"“值。在控制台中,文本值发生变化,但在网页中保持不变。
private void notify(string msg)
{
notification.Text = msg;
System.Threading.Timer timer = null;
timer = new System.Threading.Timer((obj) =>
{
bar();
timer.Dispose();
},
null, 3000, System.Threading.Timeout.Infinite);
}
private void bar()
{
notification.Text="";
System.Diagnostics.Debug.WriteLine(notification.Text); //Output ""
}
发布于 2018-08-08 08:38:33
关于它,你将不得不在客户端使用setInterval(func,3000)使用javascript.In,这样当Notify在客户端被调用3000秒后,在客户端隐藏到以下代码的Label.Use中
设计文件(.aspx)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function Hide()
{
document.getElementById("notification").hidden = true;
}
setInterval(Hide, 3000);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="notification" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
notify代码文件( Code File,.cs)在服务器端调用notify方法时的。我是通过Page_Load调用的,它将由您自己选择。
protected void Page_Load(object sender, EventArgs e)
{
notify("ok");
}
private void notify(string msg)
{
notification.Text = msg;
}
https://stackoverflow.com/questions/51736911
复制相似问题