ClientScript.RegisterStartupScript将仅以表格形式工作吗? [英] Will ClientScript.RegisterStartupScript work only in forms?

查看:94
本文介绍了ClientScript.RegisterStartupScript将仅以表格形式工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在文件背后的aspx代码中执行一些javascript代码.我在互联网上看到的所有示例都涉及按钮单击处理程序中的代码...但是,出于我的需要,我需要使用javascript将数据发布到使用APE的客户端...

I am trying to execute some javascript code in my aspx code behind file. All the examples i have seen on the internet involves code in handler of a button click... But, for my need, i need to use javascript to publish data to clients using APE...

我从简单地拥有

 ClientScript.RegisterStartupScript(this.GetType(),"alert","alert('hi');",true);

但是,它不起作用.当我没有表格时,有人可以解释我执行JavaScript代码所要做的事情吗?

But, it doesn't work. Can someone explain what i have to do to execute javascript code when i dont have a form ?

编辑:我有一个线程,每5s执行一次.该线程应每次执行javascript代码.你知道我该怎么做吗?谢谢

EDIT: I have a thread that executes every 5s . This thread should execute a javascript code everytime. Do u know how i can do this? thanks

推荐答案

是的,从ASP.NET 2.0 [1]开始,除非脚本包含将runat属性设置为服务器"的表单,否则该脚本不会添加到页面中. :

Yes, as of ASP.NET 2.0[1] the script will not be added to the page unless it contains a form with the runat attribute set to "server":

<form runat="server">

您不需要在页面上添加任何控件,因此您不能仅将表单添加到.aspx文件中吗?或者,为什么不将对脚本的调用直接添加到页面呢?例如

You don't need to add any controls to the page, so can't you just add the form to your .aspx file? Alternatively, why not just add the call to the script directly to the page? E.g.

<body onload="doStuff();">

[1] http://www.haiders.net/post/Rendering-Client-Script-in-ASPNET-20-Behavior-changes.aspx

这篇关于ClientScript.RegisterStartupScript将仅以表格形式工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆