Solved

Timer

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

Independent Software Vendors: 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

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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