0

The Timer is defined like this:

<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="1000" Enabled="false" />

When calling $find("<%= Timer1.ClientID %>")._startTimer(); I'm getting this error:

Microsoft JScript runtime error: Unable to get value of the property '_startTimer': object is null or undefined

and when calling $('#Timer1')._startTimer(); I'm getting this error:

Microsoft JScript runtime error: Object doesn't support property or method '_startTimer'

Any advice will be welcome.

1 Answer 1

1

Try passing $find() the shorter server-side (or "Component") ID:

$find("Timer1")._startTimer();

You may also be able to use $get() with the ClientID:

$get("<%= Timer1.ClientID %>")._startTimer();

With jQuery, pass it the ClientID as with $get() and use .get(0) to retrieve the DOM Object from the jQuery collection:

$('#<%= Timer1.ClientID %>').get(0)._startTimer();
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks a lot, works great now. Which method is preferred? By the way, is there a way to just invoke the Tick event without starting the timer?
@toy4fun Each method is a viable option. Just use the one that seems best to you. As for raising the Tick event, the control is defined with a _raiseTick method, which _startTimer calls with a setTimeout.
If I understood correctly, I can call _raiseTick without enabling the timer?
@toy4fun For that, you'll want to call _stopTimer after _raiseTick, as _raiseTick calls _startTimer itself to setup the next Tick.
So now my code looks like that: $find("Timer1")._raiseTick(); $find("Timer1")._stopTimer();. Thanks Again.

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.