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
精彩评论