how to call javascript function from delegate AsyncCallback function?
I am getting location date time from a async delegate call. I want to set lable value to date time value returned by that delegate method.But the problem is this is getting rendered before the asynchronous method completes.and I cant wait for this async method because it uses a third party service that is very slow. So I have implemented a Async callback function and inside that call back function I want to run a javascript script functio开发者_如何学JAVAn
.But the problem is it not populating the javascript method. Here my code-
public void DateTimeCallBack(IAsyncResult asy)
{
AsyncResult result = (AsyncResult)asy;
DateTimeDelegate dtdel = (DateTimeDelegate)result.AsyncDelegate;
lblDateTime.Text = dtdel.EndInvoke(asy).ToString("MMM dd, yyyy"); // this is not setting the value to lable
// so I want to use javascript
ScriptManager.RegisterStartupScript(this, this.GetType(), "ScriptNo", "window.setTimeout(\"alert('Hello');\",0);", true);
}
this is not populatiog javascript alert message.Does AsyncCallback method not support this way of javascript?? OR there is any other way to do the same?
You don't "call" javascript functions from the server side. You output javascript to the web browser, which then executes everything within the script tags that your server generated. I'm not sure what your code is attempting to do, I'm not even sure what language that is since you didn't say(I'm guessing it's C#), but you need to have a clear understanding of the difference between server side code and client-side code, and how they interact.
Server side code only generates the javascript that your browser will run, it cannot directly affect the runtime of it.
Likewise javascript can't directly "call" functions on the server side either, you can only make an HTTP GET or POST request, which then is handled by server side code.
精彩评论