作者:红杏出墙的爱_408 | 来源:互联网 | 2023-09-17 18:24
IvegotajavascriptfunctioninASP.Netcalledtimer().Inthecode-behind,Ivegotan我在ASP.Net中
I've got a Javascript function in ASP.Net called timer(). In the code-behind, I've got an
我在ASP.Net中有一个叫做timer()的Javascript函数。在代码隐藏中,我有一个
if (!Page.IsPostBack)
and inside of that I've got a function that fires this line:
并且在其中我有一个触发此行的函数:
ScriptManager.RegisterClientScriptBlock(UpdatePanel4, this.GetType(), "timerscript", "timer()", true);
When I run this, I get the following error:
当我运行它时,我收到以下错误:
Microsoft JScript Runtime Error: 'timer' is undefined
When I look at the code, it looks like the site.master has loaded, but nothing on the page I'm actually loading has loaded yet.
当我查看代码时,它看起来像是site.master已加载,但我实际加载的页面上没有任何内容已加载。
I tried putting my timer code on site.master, but it references a specific field on the page I've got the timer on, and it won't load.
我尝试将我的计时器代码放在site.master上,但是它引用了我已经启用了计时器的页面上的特定字段,并且它不会加载。
Here is my timer script:
这是我的计时器脚本:
So, can anyone either a) tell me how to get this script to run when I load my page, or b) tell me how to edit this script so it will run off site.master?
所以,任何人都可以a)告诉我如何在我加载页面时运行此脚本,或者b)告诉我如何编辑此脚本以便它将运行在site.master之外?
I should add that the ScriptManager.RegisterClientScriptBlock line works fine in all other places where it's firing after the page has loaded, so I know it works. The only place it doesn't work is on the initial page load.
我应该补充一点,ScriptManager.RegisterClientScriptBlock行在页面加载后触发的所有其他地方都能正常工作,所以我知道它有效。它不起作用的唯一地方是初始页面加载。
2 个解决方案