Solved

Timer

Posted on 2006-10-26
8
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modal Popup Extender control 1 53
Object Oriented Programming, C#, referencing, scoping. 13 86
TimeZone, day light savings, Sql server, asp.net 6 39
Finding the IIS version 5 38
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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