   [web] ASP.NET 2.0, C#, AJAX.  How to send a client a string?
  First post here in a while, and Im just moving into playing around with web programming, so thanks for listening!  Now here is my problem :) :Im currently programming in ASP.NET 2.0 with AJAX(JScript client-side) and C#(server-side).  I currently have the client able from jscript to call up a server-side function and serialize/deserialize the string using JSON and custom converters.My problem now comes in where I want the server to call the client side by sending a string(or any object) without the client initiating the conversation.  I know I can have a timer on the client side go off and then do a callback to the server-side function, but I dont want a timer always going off.So right now I have created a custom control extending System.Web.UI.WebControls.CompositeControl, IScriptControl, and ICallbackEventHandler.  I have a registered client script block using Page.ClientScript.RegisterClientScriptBlock(...) that was help built using Page.ClientScript.GetCallbackEventReference(...) - which all works great.So final question is, how do I call up a client-side function from the server-side without using a timer on client to initiate conversation?Thanks much and if anyone has any information or another forum recommendation to post on I would GREATLY appreciate it!-Brad   
  What about//It executes the code after the page is done loadingthis.UnLoad +=  new EventHandler(    delegate{  HttpContext.Current.Response.Write(@"  <script type='text/&#106avascript'> call&#106avascriptClientCode(); &lt;/script&gt;");<br>    });<br><br>//Or<br><br>//Execute the code before the any asp.net page is executed<br><br>//Create a new Global.asax file for your web application and add the following //code to it<br><br>protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)<br>{<br>Page page = HttpContext.Current.CurrentHandler as Page;<br>if(page != null) {<br>    HttpContext.Current.Response.Write(@"<br>  &lt;script type='text/&#106avascript'&gt; call&#106avascriptClientCode(); &lt;/script&gt;");<br>}<br>}<br></pre>;Quote:Original post by xsirxxSo final question is, how do I call up a client-side function from the server-side without using a timer on client to initiate conversation?Think about what you're asking. Typically, a web client requests a page from a server, which returns it, and then the transaction is complete. What you're wanting is for the server to then contact the client again... but how? That web client may no longer exist (the browser closed), the computer may not be switched on, it may now be at a different address or share that address with many others (internet vagaries). The web isn't designed to do what you want to do.Now, there is a sort of hack for doing this, these days called Comet, but you really don't want to go down this route without first understanding why it is the wrong view to take in 99% of cases. Web systems should fundamentally be about the client requesting things from a server. That is what the system is designed for and that is also what the user expects. If you want long-running bidirectional connections, that is where something like Java or Flash comes in, or even non-web protocols.   ;  Thank you for the replys guys!  kylotan:Yea I realize that, but some types of applications would be better off if it had bi-directional.  For instance a chat application.  If a chat application had to constantly ask the server every couple seconds for a response, it would be a huge waste of bandwidth.  I just assumed that there would be a way to do this given the strength of the web now....rpgmaker:Those methods are really just one time events basically still called by the client right?  Or can those events be fired off by the server when it wants?  If so if you would be so kind as to throw a link my way?  Right now I dont really have any post backs running except the first or of course on a refresh.  I am using all call-backs which leads to almost 0 visible notices of a refresh.  Then I have the client calling the server through a timer-callback and then I shoot back an array of JSON objects which are really my events to update the client....  But if I can take that timer out and somehow fire off a HttpResponse without a request, well that would be awesome!Thanks!;Quote:Original post by xsirxxYea I realize that, but some types of applications would be better off if it had bi-directional.  For instance a chat application.  If a chat application had to constantly ask the server every couple seconds for a response, it would be a huge waste of bandwidth.  I just assumed that there would be a way to do this given the strength of the web now....Well, no, because that's not how the web works. Sorry. :)  Clients call servers, not the other way around. If you want other stuff, typically you step outside of HTTP and the WWW.   ;  I wasnt saying it should, I was just saying that I thought there would have been a way.  I think the web is really growing beyond what it was initially built for.  Also I noticed on wikipedia that HTTP5 supports Comet, or Comet like bi-directional talking.Thanks for your help!--Brad   