Solved

Timer

Posted on 2006-10-26
8
306 Views
Last Modified: 2007-01-12
Hi,
How can I add following Code  in  Usercontrol of  ASP.NET.
i HAVE A USERCONTROL in that i have Time Label and I want to show time:
Since there is no head, body tag in user control,  how can i add following code in ASP.NET USERCONTROL:

<HEAD>
<script language="JavaScript" type="text/javascript">
function sivamtime() {
      now=new Date();
      hour=now.getHours();
      min=now.getMinutes();
      sec=now.getSeconds();

if (min<=9) {min="0"+min; }
if (sec<=9) {sec="0"+sec; }if (hour<10) {hour="0"+hour; }

  document.Form1.LBLTIME.value = hour + ":" + min + ":" + sec;
 
setTimeout("sivamtime()", 1000);
}
</script>
</HEAD>

<BODY onload="sivamtime()">
0
Comment
Question by:sohrabus
  • 4
8 Comments
 
LVL 6

Expert Comment

by:Niraj_Singh
ID: 17818538

 Just go to code behind of the user control ( .ascx.cs for C#) and add the following code on the page load event.

      Label1.Text=DateTime.Now.ToString();
 
 You have to place this user control on .aspx page. Label1 will display the time of the machine when the .aspx page is loaded.
 i hope it would help you...please let me know if u have any problem doing so.
0
 

Author Comment

by:sohrabus
ID: 17824520
Dear Niraj,
Presently I'm doing the same u have explained. I made User control n put label for time and then attach this user control to my all .aspx pages.  Till here OK.

But now My requirement is that   I want   a   tick time  which is not possible in asp.net    and  it is possible   from  JavaScript.  
The above code which i wrote 1st time is giving tick time  BUT how can i add THAT code in ASP.NET USERCONTROL since  <Head>  and <Body> Tag is used in this code.

Can I use   <Head>  and <Body>  <Form>  tag in USERCONTROL.
0
 
LVL 6

Accepted Solution

by:
Niraj_Singh earned 125 total points
ID: 17897577

 hi sohrabus,
  u will have to modify the user control a bit. i have created the functionality that you require using a button instead of label.use the code below in the user control. i hope this would solve ur problem.

<INPUT type="button" id="btnTime">
<script language="javascript">
      function sivamtime()
      {
            var dte = new Date();
            hour=dte.getHours();
            min=dte.getMinutes();
            sec=dte.getSeconds();

            if (min<=9) {min="0"+min; }
            if (sec<=9) {sec="0"+sec; }
            if (hour<10) {hour="0"+hour;}

            document.getElementById("btnTime").value = hour + ":" + min + ":" + sec;
            setTimeout("sivamtime()", 1000);
      }
   sivamtime();
</script>
0
 
LVL 6

Expert Comment

by:Niraj_Singh
ID: 17897636

 <INPUT type="button" id="btnTime" style="BACKGROUND-COLOR: transparent">

 you can modify the button if u want the background to b transparent....
0
 
LVL 6

Expert Comment

by:Niraj_Singh
ID: 17994090

 hi sohrabus,
  i was waiting to hear from you. Did the above solution solved your problem or not. If you could tell me.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now