开发者

Will ClientScript.RegisterStartupScript work only in forms?

开发者 https://www.devze.com 2023-03-17 15:28 出处:网络
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 java

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...

I started by simply having

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

But, it doesn't work. C开发者_开发知识库an someone explain what i have to do to execute javascript code when i dont have a form ?

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


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">

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号