0

I need to create a timer in an ASP.NET web page.

I have tested some JavaScript code like:

window.onload = function WindowLoad(event) {
    setTimeout(function () { alert("DoIT") }, 60000);
}

and it works like expected but when I replace the alert with a call to a C# function like:

window.onload = function WindowLoad(event) {
    setTimeout(function () { <% doIt(); %> }, 60000);
}

the function works on the load of the page and not after the specified period.

1
  • 1
    I would suggest looking at Ajax for calling a Server Side function. Commented Jul 6, 2013 at 20:57

2 Answers 2

3

<% doIt() %> runs during the server side process, not on client. If you want to do something on the server side you should create a webmethod and make a post to it.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this blog post, this should be what you are looking for: http://deebujacob.blogspot.com/2012/01/aspnet-ajax-web-method-call-using.html

It's like other people sad you can not call server side functions directly from javascript you have to make a request, that's is way good God gave as ajax :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.