Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Timer

Posted on 2006-10-26
8
Medium Priority
?
328 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 500 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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

609 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