JavaScript variable from ASP form?
-
Here's my situation. I've got an ASPX page that needs to be refreshed with new content every few seconds, but that amount of time is variable. I'm sending that variable to the page from the server-side application on every refresh. That way, theoretically, the page can automatically refresh when that variable amount of time is elapsed and thereby get a new amount of time to count down. Setting up a JavaScript reload function is easy enough, but I can't find a way to get that ASP variable into the Javascript, as the JavaScript seems to be able to only access HTML form components and not ASP form objects. So, I either need a way to get an ASP variable into the JavaScript, or I need a different client-side script that can actually get that variable from an ASP control and is still capable of causing a PostBack like JavaScript can. Any ideas? Thanks for your help!
-
Here's my situation. I've got an ASPX page that needs to be refreshed with new content every few seconds, but that amount of time is variable. I'm sending that variable to the page from the server-side application on every refresh. That way, theoretically, the page can automatically refresh when that variable amount of time is elapsed and thereby get a new amount of time to count down. Setting up a JavaScript reload function is easy enough, but I can't find a way to get that ASP variable into the Javascript, as the JavaScript seems to be able to only access HTML form components and not ASP form objects. So, I either need a way to get an ASP variable into the JavaScript, or I need a different client-side script that can actually get that variable from an ASP control and is still capable of causing a PostBack like JavaScript can. Any ideas? Thanks for your help!
Well if you think about it, all the server is doing is outputting text, whether that text is HTML, javascript etc. So you could output something like this: setTimeOut(<%= Some Variable calculated on the server%>); This would be sent to the client like: setTimeOut(500); Of course this is oversimplified, you could create custom controls that are a little more elegant and reusable.