0

I had not used ScriptManager on my MasterPage as it was not required when I started developing the project, so I have an individual ScriptManager and UpdatePanel for each content page.

In the MasterPage now I've added a label which shows the current system time, and my client wants it to change asynchronously and give a live clock feeling. Can I change the label text in the master page from the content page using Timer? So far I'm unable to achieve this, as I can't use an UpdatePanel also in the MasterPage because there is no ScriptManager tag.

So is there a way to achieve this?

Adi Lester
  • 24,731
  • 12
  • 95
  • 110
Dharmendra Kumar Singh
  • 2,979
  • 10
  • 46
  • 63
  • Yes, you can get the Master page instance using `((YourMasterClass)this.Master).Whatever()`, but the best solution would be adding a ScriptManager to the Master, removing it from the content pages and implementing this clock at the Master page only. The clock is a Master's responsability. – Andre Calil Aug 03 '12 at 13:09
  • 1
    Why you don't use plain javascript on master page? – Yuriy Rozhovetskiy Aug 03 '12 at 13:14

1 Answers1

0

Thanks @ Yuriy Rozhovetskiy, From your suggestion i had created a simple javascript and called that javascript on Master page body on load and its working fine. Please find code below which may help to some one who also have same requirement:-

Javascript Function:-

<script type="text/jscript">
    function clock(){ 
      var d = new Date(); 
      var h = d.getHours(); 
      var m = d.getMinutes(); 
      var s = d.getSeconds(); 
      $('#clock').html(h+"<span class='colon'>:</span>"+m+"<span class='colon'>:</span>"+s); 
    //  $('.colon').fadeTo(1000, .2); 
      setTimeout(clock, 1000); 
    } 

<body onload="clock()">

Added this to display clock on master page.

<span id="clock" style="font-family:Calibri;color:White;font-weight:bold;font-size:1.3em;"></span>
Dharmendra Kumar Singh
  • 2,979
  • 10
  • 46
  • 63