Search code examples
c#javascriptasp.netsqlcountdown

Timer countdown sql, asp.net c#, javascript


i have the next javascript code:

 <script language="JavaScript">
  TargetDate = "12/31/2020 5:00 AM";
  BackColor = "palegreen";
  ForeColor = "navy";
  CountActive = true;
  CountStepper = -1;
  LeadingZero = true;
  DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
  FinishMessage = "the auction end"
  </script>
   <script language="JavaScript" src="countdown.js"></script>

my question is... how to do that the TargetDate will get the datetime from sql table? i have sql table with the desgin: id, auctionEndTime .... how i'm connect that to the targetdate? it is possible?


Solution

  • You could use a property in code behind to fill up the javascript directly.

    ASP.Net page:

    <script language="JavaScript">
      TargetDate = "<% = TargetDate %>"; /*this is a property in code behind*/
      BackColor = "palegreen";
      ForeColor = "navy";
      CountActive = true;
      CountStepper = -1;
      LeadingZero = true;
      DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
      FinishMessage = "the auction end"
    </script>
    <script language="JavaScript" src="countdown.js"></script>
    

    Page code behind:

    public string TargetDate{
      // Build code to get date from database
      string sql = "SELECT targetDate from Events where Event_ID = 1309";
      // execute sql
      // ...
      return dbvalue;
    }