事先声明一下,基本的方法我知道,但在运用的过程中,我发现了这么一种情况:
我在一个按钮的点击事件立即调用JS函数没有问题,但是当我的这个事件运行了
大量的运算,大概用了20秒的时间,我再在这个运算后调用JS函数,好像就不起作用了。 public void MyFunction()
{
if (this.hfQuestionNo.Value == "1")
{
this.hfQuestionNo.Value = "2"; ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "DeleteRecord('" + FormatMessage("当前电脑的时间是: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ", 是否正确 ?") + "');", true);
}
else if (this.hfQuestionNo.Value == "2")
{
this.hfQuestionNo.Value = "3"; if (this.hfConfirmTime.Value == "1")
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "ShowWaiting();", true);
}
}
else
{
this.hfQuestionNo.Value = "1"; if (this.hfConfirmTime.Value == "1")
{
MyFunction2("1"); ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "HideWaiting();", true); Response.Write("<script type='text/javascript'>function HideWaiting(){}</script>"); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>HideWaiting();</script>"); }
}
}
在以上的代码中,调用前台的JS函数的语句:
ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "DeleteRecord('" + FormatMessage("当前电脑的时间是: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ", 是否正确 ?") + "');", true);和 ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "ShowWaiting();", true);都执行了,但是最后的几个没执行:
ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "HideWaiting();", true); Response.Write("<script type='text/javascript'>function HideWaiting(){}</script>"); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>HideWaiting();</script>");其中MyFunction2("1");有大量运算的。其实我的想法是,在用户确认了操作后,因为要用较长的时间生成一个文件,所以在页面上显示一个等待的图片和提示,这都没有问题。问题是,文件产生完毕后,下载到了本机后,我想把等待的信息和图片隐藏掉,就写了一个JS函数去实现,但这时好像一直没有执行这个函数,尽管我用了各种方法。请告诉指点一下。
我在一个按钮的点击事件立即调用JS函数没有问题,但是当我的这个事件运行了
大量的运算,大概用了20秒的时间,我再在这个运算后调用JS函数,好像就不起作用了。 public void MyFunction()
{
if (this.hfQuestionNo.Value == "1")
{
this.hfQuestionNo.Value = "2"; ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "DeleteRecord('" + FormatMessage("当前电脑的时间是: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ", 是否正确 ?") + "');", true);
}
else if (this.hfQuestionNo.Value == "2")
{
this.hfQuestionNo.Value = "3"; if (this.hfConfirmTime.Value == "1")
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "ShowWaiting();", true);
}
}
else
{
this.hfQuestionNo.Value = "1"; if (this.hfConfirmTime.Value == "1")
{
MyFunction2("1"); ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "HideWaiting();", true); Response.Write("<script type='text/javascript'>function HideWaiting(){}</script>"); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>HideWaiting();</script>"); }
}
}
在以上的代码中,调用前台的JS函数的语句:
ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "DeleteRecord('" + FormatMessage("当前电脑的时间是: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ", 是否正确 ?") + "');", true);和 ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "ShowWaiting();", true);都执行了,但是最后的几个没执行:
ScriptManager.RegisterStartupScript(this, this.GetType(), "JSFunction", "HideWaiting();", true); Response.Write("<script type='text/javascript'>function HideWaiting(){}</script>"); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>HideWaiting();</script>");其中MyFunction2("1");有大量运算的。其实我的想法是,在用户确认了操作后,因为要用较长的时间生成一个文件,所以在页面上显示一个等待的图片和提示,这都没有问题。问题是,文件产生完毕后,下载到了本机后,我想把等待的信息和图片隐藏掉,就写了一个JS函数去实现,但这时好像一直没有执行这个函数,尽管我用了各种方法。请告诉指点一下。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货