Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

How to use a Javascript with asp.net

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
MrMackFXP
Asked:
MrMackFXP
  • 2
2 Solutions
 
mmayrellCommented:
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
 
yogic_flyerCommented:
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
 
MrMackFXPAuthor Commented:
Can Javascript call an ASP.net method?
0
 
yogic_flyerCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now