Solved

How to use a Javascript with asp.net

Posted on 2004-07-30
6
228 Views
Last Modified: 2012-05-05
Hello all,

I have a Javascript timer that works so so with ASP.net.... I have 2 asp.net buttons for my online game that gives a pause or adds 15sec to the timer. It may be triggered only if you have pauses left (3 per game) and if you have adds left (6 per game).

My timer starts at 180 sec and goes down to 0. When i trigger an ASP.net button to pause my timer, it reset the timer.... Same thing for the adds...

My timer is started onLoad of my Page. Heres how my timer starts in my Timer.js file:
function StartCountDown()
{
      ShowNewTime(iSecond);
      oTimer = window.setTimeout("IncrementSecond();",1000);
}
function IncrementSecond()
{
      iSecond = iSecond - 1;
      
      ShowNewTime(iSecond);
      
      if (iSecond >= 0)
      {
            oTimer = window.setTimeout("IncrementSecond();",1000);
      }else
      {
            
            window.close();
      }
}

I'll be around all day if you dont understand my problem. All i want its to stop/adds time to the timer (ONLY if my variable nbPauses > 0)

Thankee in advance
0
Comment
Question by:MrMackFXP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
mmayrell earned 125 total points
ID: 11677249
Why are you using asp.net buttons?  Web controls will cause the page to post back reseting your timers.  I would suggest using <input type="button"> for this type of application.

-Michael
0
 
LVL 1

Assisted Solution

by:yogic_flyer
yogic_flyer earned 125 total points
ID: 11677846
I would tend to agree and say that using an <input type="button"> in this case seems to be the better bet.
However, if you still wanted to use asp.net buttons to execute javascript, you could use (for example)
myButton.Attributes.Add("onclick",@"return confirm('Are you sure you want to click this button?');");
in your code behind. This should cause a javascript Yes/Cancel dialog to appear before the postback and server side button event.
0
 

Author Comment

by:MrMackFXP
ID: 11684990
Can Javascript call an ASP.net method?
0
 
LVL 1

Expert Comment

by:yogic_flyer
ID: 11689003
You need to generate a postback to execute server side methods. This article might help some...hopefully.

http://www.xefteri.com/articles/dec102002/default.aspx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Javascript Regex 7 20
converting document.write() to innerHTML 7 44
Html split(text) Part2 6 20
center navbar (navigation menu) on web page 3 14
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question