问题描述
使用MSVS Express 2012 for Web
使用ASP.NET,C#
我有一个WebForm:
- 一个带有UpdatePanel的ScriptManager,它包含一个标签。
标签正在使用正在下载的一些HTML数据进行更新。从另一个网站解析。工作正常。
我还有一个javascript(来自远程网站进行联合),它修改了某个类中的某些内容。
例如
Using MSVS Express 2012 for Web
With ASP.NET, C#
I have on a WebForm:
- A ScriptManager, with an UpdatePanel, which contains a Label.
The Label is being updated with some HTML data that it is downloading & parsing from another web site. Works fine.
I also have a javascript (from a remote web site for syndication) that modifies some of the content that is within a certain class.
For example
<a class="remotesite-class" href="someurl">Some Temporary Text</a>
这是由其他人的javascript改变的网站。
This is changed by the javascript from the other site.
<a class="remotesite-class" href="someurl">Text Content From The JavaScript</a>
这适用于大约一半的时间。
为什么?
好吧,如果我的页面加载太长时间,似乎javascript运行太晚了。我不确定这是不是为什么,但这就是我所相信的。因为如果我刷新它并使用数据的缓存版本,它会更频繁地按预期工作。
(另外,我知道远程javascript没有问题)
我正在将javascript添加到我的页面中:
This works about the half time.
Why?
Well, it seems that the javascript is running too late if my page takes too long to load. I don''t know for sure if that is why, but that''s what I believe. Because if I refresh it and use a cached version of the data, it works as expected more often.
(Also, there is no problem that I know of with the remote javascript)
I''m adding the javascript to my page like this:
const string scriptKey = "remotescript";
Page.ClientScript.RegisterStartupScript(Page.GetType(), scriptKey, "<script type=\"text/javascript\" src=\"http://www.remotesite.com/js/script.js\"></script>");
我认为只有在页面加载后才会执行。
但是由于标签内容可以更改在它加载之后,它并不总是有效。
当我知道内容完成时,有没有办法执行脚本(到我的选择)?或者,当标签中的内容发生变化时,如何确保它运行?
我希望我已经包含了足够的信息。不幸的是我无法显示整个代码,但如果需要我会回答问题。
感谢您的时间。
Which I was led to believe only executes after the page is loaded.
But since the Label content can change after it''s "loaded", it''s not always working.
Is there a way to execute the script when I know the content is complete (to my choice)? Or how can I ensure that it runs when the content in the Label changes?
I hope I''ve included enough info. Unfortunately I can''t show the entire code, but I''ll answer questions if needed.
Thanks for your time.
推荐答案
这篇关于Javascript运行'太晚'来更改修改后的ASP.NET Label内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!