Solved

Timer

Posted on 2006-10-26
8
308 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

22 Experts available now in Live!

Get 1:1 Help Now