[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

i need to implement javascript function in my ascx page.

Posted on 2009-04-08
4
Medium Priority
?
463 Views
Last Modified: 2012-05-06
<script type="text/javascript">
<!--

function updateClock ( )
{
  var currentTime = new Date ( );

  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );

  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

  // Convert the hours component to 12-hour format if needed
  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

  // Convert an hours component of "0" to "12"
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

  // Update the time display
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}

// -->
</script>
http://www.elated.com/articles/creating-a-javascript-clock/

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="uxLogin.ascx.cs" Inherits="OmegaLove.Web.UI.uxLogin" %>
i need to implement this in the theTime textbox below or if there is another way that is great
i just want it working.
 
 
<div id="loginbox">
             <asp:LoginView ID="LoginView1" runat="server">
             <AnonymousTemplate>
               <asp:Login ID="LoginStatus" runat="server" Height="31px" width="100%" FailureAction="RedirectToLoginPage"
                    onloggedin="LoginStatus_LoggedIn" onloggingin="LoginStatus_LoggingIn">
                  <LayoutTemplate>
                   <table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                           <td nowrap="nowrap" width="25%">
                           <asp:Label runat="server" ID="lblUserName" AssociatedControlID="UserName" Text="Username:"  />
                           <asp:TextBox id="UserName" runat="server" BorderColor="DarkGray"  
                                   BorderStyle="Inset" BorderWidth="2px" Width="125px" />
                           </td>
                            
                           <td width="8px" style="text-align: left;" valign="middle">
                           <asp:RequiredFieldValidator ID="valRequireUserName" runat="server" SetFocusOnError="True"
                                 ControlToValidate="UserName" Text="*" ValidationGroup="Login"  
                                   Font-Bold="True"  />                     
                           </td>
                          
                          <td nowrap="nowrap" width="25%">
                          <asp:Label ID="lblPassword" runat="server" AssociatedControlID="Password" Text="Password:" />
                          <asp:TextBox ID="Password" runat="server" TextMode="Password"
                                   BorderColor="DarkGray" BorderStyle="Inset" BorderWidth="2px" 
                                  Width="125px" />
                          </td>
                          
                          <td width="8px" style="text-align: left;" valign="middle">
                                <asp:RequiredFieldValidator ID="valRequirePassword" runat="server" 
                                    ControlToValidate="Password" SetFocusOnError="True" Text="*" 
                                    ValidationGroup="Login" Font-Bold="True" />
                          </td>
                          
                          <td width="25%">
                               <asp:Button CssClass="button-login" validationgroup="Login" 
                                   CommandName="Login" ID="btnLogin" 
                                   runat="server" Text="Login" Font-Bold="True" />
                                    
                          </td>
                              
                                        
                        </tr>
                        
                        <tr>
                            <td width="100%" colspan="5" style="text-align: right;">
                                <asp:HyperLink ID="lnkRegister" runat="server" NavigateUrl="~/Secure/Register.aspx">Create New Account 
                                </asp:HyperLink>
                                | <asp:HyperLink ID="lnkPasswordRecovery" runat="server" 
                                    NavigateUrl="~/Secure/PasswordRecovery.aspx">Forgot 
                                password?</asp:HyperLink>
                            </td>
                        </tr>
 
                        <tr>
                            <td width="100%" colspan="5" style="text-align: right;">
                               <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                               <input type="text" class="value" name="theTime" size="27" readonly="readonly" style="border: 0px;">
                            </td>
                        </tr>
                     </table>
                    </LayoutTemplate>
               </asp:Login>
              </AnonymousTemplate>
                
            <LoggedInTemplate>
               <div id="welcomebox">
                  <asp:LoginName ID="LoginName1" runat="server" FormatString="Welcome {0}" />
                  <asp:Button CssClass="button-login" ID="btnLogout" runat="server" Text="Logout" Font-Bold="True" 
                   OnClick="btnLogout_Click" /><br />
                   <input type="text" class="value" name="theTime" size="27" readonly="readonly" style="border: 0px;">
              </div>
            </LoggedInTemplate>
         </asp:LoginView>
    
                 
                
        </div>

Open in new window

0
Comment
Question by:mathieu_cupryk
[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
  • 2
  • 2
4 Comments
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 24113244
Hi mathieu_cupryk,
You just need to put one control inside the ascx page to display the clock time that mentioned in the article.
You can arrange the textbox - "clock" based on your preferred position.
Here is the attempt:

</script>
function updateClock ( )
{
  var currentTime = new Date ( );

  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );

  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

  // Convert the hours component to 12-hour format if needed
  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

  // Convert an hours component of "0" to "12"
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

  // Update the time display (Change the control name here)
  document.getElementById("clock").value = currentTimeString;
}

window.onload=function(){
      setInterval('updateClock()', 1000 );
}
</script>

<input type=text ID="clock" style="border:0"/>
      
<div id="loginbox">
....






0
 

Author Comment

by:mathieu_cupryk
ID: 24113724
 'document.getElementById(...)' is null or not an object



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>

</title><link href="App_Themes/PlainHtml/Commented.css" type="text/css" rel="stylesheet" /><link href="App_Themes/PlainHtml/Default.css" type="text/css" rel="stylesheet" /><link href="App_Themes/PlainHtml/Print.css" type="text/css" rel="stylesheet" /><link href="App_Themes/PlainHtml/StyleLayout.css" type="text/css" rel="stylesheet" /><link href="App_Themes/PlainHtml/StyleSheet.css" type="text/css" rel="stylesheet" /><link href="App_Themes/PlainHtml/TabView.css" type="text/css" rel="stylesheet" /></head>
<body>
    <form method="post" action="WebForm3.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="form1">
<div>
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTQyNTYwNzA5NGRk7SMwNpjow2dh1w2Bpq982GtHcKQ=" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


<script src="/WebResource.axd?d=kuJdcXdIl8rhV6ERZYH5bg2&amp;t=633595156183430636" type="text/javascript"></script>


<script src="/WebResource.axd?d=C7tNH0ii8HjnXcc78mYxte6OgsA2zjvS8IkfoCVVISE1&amp;t=633595156183430636" type="text/javascript"></script>
<script src="/WebResource.axd?d=rxuiwK0usmvLcZJD7TjJnA2&amp;t=633595156183430636" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function WebForm_OnSubmit() {
if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
return true;
}
//]]>
</script>

<div>

      <input type="hidden" name="__SCROLLPOSITIONX" id="__SCROLLPOSITIONX" value="0" />
      <input type="hidden" name="__SCROLLPOSITIONY" id="__SCROLLPOSITIONY" value="0" />
      <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBALm8aOVCQLKpaeYDgLDici3DwKvi+2dATCwpzbv1EDRGSEZ6caDFzLbEZCL" />
</div>
    <div>
           
<script type="text/javascript">
<!--

    function updateClock() {
        var currentTime = new Date();

        var currentHours = currentTime.getHours();
        var currentMinutes = currentTime.getMinutes();
        var currentSeconds = currentTime.getSeconds();

        // Pad the minutes and seconds with leading zeros, if required
        currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
        currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;

        // Choose either "AM" or "PM" as appropriate
        var timeOfDay = (currentHours < 12) ? "AM" : "PM";

        // Convert the hours component to 12-hour format if needed
        currentHours = (currentHours > 12) ? currentHours - 12 : currentHours;

        // Convert an hours component of "0" to "12"
        currentHours = (currentHours == 0) ? 12 : currentHours;

        // Compose the string for display
        var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

        // Update the time display
        //document.getElementById("clock").firstChild.nodeValue = currentTimeString;
        document.getElementById("clock").value = currentTimeString;
    }
        window.onload = function() {
        setInterval('updateClock()', 1000);
    }
// -->
</script>

<div id="loginbox">
             
               <table id="uxLogin1_LoginView1_LoginStatus" cellspacing="0" cellpadding="0" border="0" style="height:31px;width:100%;border-collapse:collapse;">
      <tr>
            <td>
                   <table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                           <td nowrap="nowrap" width="25%">
                           <label for="uxLogin1_LoginView1_LoginStatus_UserName" id="uxLogin1_LoginView1_LoginStatus_lblUserName">Username:</label>
                           <input name="uxLogin1$LoginView1$LoginStatus$UserName" type="text" id="uxLogin1_LoginView1_LoginStatus_UserName" style="border-color:DarkGray;border-width:2px;border-style:Inset;width:125px;" />
                           </td>
                           
                           <td width="8px" style="text-align: left;" valign="middle">
                           <span id="uxLogin1_LoginView1_LoginStatus_valRequireUserName" style="color:Red;font-weight:bold;visibility:hidden;">*</span>                    
                           </td>
                         
                          <td nowrap="nowrap" width="25%">
                          <label for="uxLogin1_LoginView1_LoginStatus_Password" id="uxLogin1_LoginView1_LoginStatus_lblPassword">Password:</label>
                          <input name="uxLogin1$LoginView1$LoginStatus$Password" type="password" id="uxLogin1_LoginView1_LoginStatus_Password" style="border-color:DarkGray;border-width:2px;border-style:Inset;width:125px;" />
                          </td>
                         
                          <td width="8px" style="text-align: left;" valign="middle">
                                <span id="uxLogin1_LoginView1_LoginStatus_valRequirePassword" style="color:Red;font-weight:bold;visibility:hidden;">*</span>
                          </td>
                         
                          <td width="25%">
                               <input type="submit" name="uxLogin1$LoginView1$LoginStatus$btnLogin" value="Login" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;uxLogin1$LoginView1$LoginStatus$btnLogin&quot;, &quot;&quot;, true, &quot;Login&quot;, &quot;&quot;, false, false))" id="uxLogin1_LoginView1_LoginStatus_btnLogin" class="button-login" style="font-weight:bold;" />
                                   
                          </td>
                             
                                       
                        </tr>
                       
                        <tr>
                            <td width="100%" colspan="5" style="text-align: right;">
                                <a id="uxLogin1_LoginView1_LoginStatus_lnkRegister" href="Secure/Register.aspx">Create New Account
                                </a>
                                | <a id="uxLogin1_LoginView1_LoginStatus_lnkPasswordRecovery" href="Secure/PasswordRecovery.aspx">Forgot
                                password?</a>
                            </td>
                        </tr>

                        <tr>
                            <td width="100%" colspan="5" style="text-align: right;">
                               
                               <input type="text" class="value" name="clock" size="27" readonly="readonly" style="border: 0px;">
                            </td>
                        </tr>
                     </table>
                    </td>
      </tr>
</table>
             
   
0                  
               
        </div>
       
    </div>
   
<script type="text/javascript">
//<![CDATA[
var Page_Validators =  new Array(document.getElementById("uxLogin1_LoginView1_LoginStatus_valRequireUserName"), document.getElementById("uxLogin1_LoginView1_LoginStatus_valRequirePassword"));
//]]>
</script>

<script type="text/javascript">
//<![CDATA[
var uxLogin1_LoginView1_LoginStatus_valRequireUserName = document.all ? document.all["uxLogin1_LoginView1_LoginStatus_valRequireUserName"] : document.getElementById("uxLogin1_LoginView1_LoginStatus_valRequireUserName");
uxLogin1_LoginView1_LoginStatus_valRequireUserName.controltovalidate = "uxLogin1_LoginView1_LoginStatus_UserName";
uxLogin1_LoginView1_LoginStatus_valRequireUserName.focusOnError = "t";
uxLogin1_LoginView1_LoginStatus_valRequireUserName.validationGroup = "Login";
uxLogin1_LoginView1_LoginStatus_valRequireUserName.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
uxLogin1_LoginView1_LoginStatus_valRequireUserName.initialvalue = "";
var uxLogin1_LoginView1_LoginStatus_valRequirePassword = document.all ? document.all["uxLogin1_LoginView1_LoginStatus_valRequirePassword"] : document.getElementById("uxLogin1_LoginView1_LoginStatus_valRequirePassword");
uxLogin1_LoginView1_LoginStatus_valRequirePassword.controltovalidate = "uxLogin1_LoginView1_LoginStatus_Password";
uxLogin1_LoginView1_LoginStatus_valRequirePassword.focusOnError = "t";
uxLogin1_LoginView1_LoginStatus_valRequirePassword.validationGroup = "Login";
uxLogin1_LoginView1_LoginStatus_valRequirePassword.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
uxLogin1_LoginView1_LoginStatus_valRequirePassword.initialvalue = "";
//]]>
</script>


<script type="text/javascript">
//<![CDATA[

var Page_ValidationActive = false;
if (typeof(ValidatorOnLoad) == "function") {
    ValidatorOnLoad();
}

function ValidatorOnSubmit() {
    if (Page_ValidationActive) {
        return ValidatorCommonOnSubmit();
    }
    else {
        return true;
    }
}
       
theForm.oldSubmit = theForm.submit;
theForm.submit = WebForm_SaveScrollPositionSubmit;

theForm.oldOnSubmit = theForm.onsubmit;
theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit;
WebForm_AutoFocus('uxLogin1_LoginView1_LoginStatus_UserName');//]]>
</script>
</form>
</body>
</html>


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="uxLogin.ascx.cs" Inherits="OmegaLove.Web.UI.uxLogin" %>
<script type="text/javascript">
<!--
 
    function updateClock() {
        var currentTime = new Date();
 
        var currentHours = currentTime.getHours();
        var currentMinutes = currentTime.getMinutes();
        var currentSeconds = currentTime.getSeconds();
 
        // Pad the minutes and seconds with leading zeros, if required
        currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
        currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;
 
        // Choose either "AM" or "PM" as appropriate
        var timeOfDay = (currentHours < 12) ? "AM" : "PM";
 
        // Convert the hours component to 12-hour format if needed
        currentHours = (currentHours > 12) ? currentHours - 12 : currentHours;
 
        // Convert an hours component of "0" to "12"
        currentHours = (currentHours == 0) ? 12 : currentHours;
 
        // Compose the string for display
        var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
 
        // Update the time display
        //document.getElementById("clock").firstChild.nodeValue = currentTimeString;
        document.getElementById("clock").value = currentTimeString;
    }
        window.onload = function() {
        setInterval('updateClock()', 1000);
    }
// -->
</script>
 
<div id="loginbox">
             <asp:LoginView ID="LoginView1" runat="server">
             <AnonymousTemplate>
               <asp:Login ID="LoginStatus" runat="server" Height="31px" width="100%" FailureAction="RedirectToLoginPage"
                    onloggedin="LoginStatus_LoggedIn" onloggingin="LoginStatus_LoggingIn">
                  <LayoutTemplate>
                   <table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                           <td nowrap="nowrap" width="25%">
                           <asp:Label runat="server" ID="lblUserName" AssociatedControlID="UserName" Text="Username:"  />
                           <asp:TextBox id="UserName" runat="server" BorderColor="DarkGray"  
                                   BorderStyle="Inset" BorderWidth="2px" Width="125px" />
                           </td>
                            
                           <td width="8px" style="text-align: left;" valign="middle">
                           <asp:RequiredFieldValidator ID="valRequireUserName" runat="server" SetFocusOnError="True"
                                 ControlToValidate="UserName" Text="*" ValidationGroup="Login"  
                                   Font-Bold="True"  />                     
                           </td>
                          
                          <td nowrap="nowrap" width="25%">
                          <asp:Label ID="lblPassword" runat="server" AssociatedControlID="Password" Text="Password:" />
                          <asp:TextBox ID="Password" runat="server" TextMode="Password"
                                   BorderColor="DarkGray" BorderStyle="Inset" BorderWidth="2px" 
                                  Width="125px" />
                          </td>
                          
                          <td width="8px" style="text-align: left;" valign="middle">
                                <asp:RequiredFieldValidator ID="valRequirePassword" runat="server" 
                                    ControlToValidate="Password" SetFocusOnError="True" Text="*" 
                                    ValidationGroup="Login" Font-Bold="True" />
                          </td>
                          
                          <td width="25%">
                               <asp:Button CssClass="button-login" validationgroup="Login" 
                                   CommandName="Login" ID="btnLogin" 
                                   runat="server" Text="Login" Font-Bold="True" />
                                    
                          </td>
                              
                                        
                        </tr>
                        
                        <tr>
                            <td width="100%" colspan="5" style="text-align: right;">
                                <asp:HyperLink ID="lnkRegister" runat="server" NavigateUrl="~/Secure/Register.aspx">Create New Account 
                                </asp:HyperLink>
                                | <asp:HyperLink ID="lnkPasswordRecovery" runat="server" 
                                    NavigateUrl="~/Secure/PasswordRecovery.aspx">Forgot 
                                password?</asp:HyperLink>
                            </td>
                        </tr>
 
                        <tr>
                            <td width="100%" colspan="5" style="text-align: right;">
                               <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                               <input type="text" class="value" name="clock" size="27" readonly="readonly" style="border: 0px;">
                            </td>
                        </tr>
                     </table>
                    </LayoutTemplate>
               </asp:Login>
              </AnonymousTemplate>
                
            <LoggedInTemplate>
               <div id="welcomebox">
                  <asp:LoginName ID="LoginName1" runat="server" FormatString="Welcome {0}" />
                  <asp:Button CssClass="button-login" ID="btnLogout" runat="server" Text="Logout" Font-Bold="True" 
                   OnClick="btnLogout_Click" /><br />
                   <input type="text" class="value" name="clock" size="27" readonly="readonly" style="border: 0px;">
              </div>
            </LoggedInTemplate>
         </asp:LoginView>          
                
        </div>
       

Open in new window

0
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 2000 total points
ID: 24113733
Hi mathieu_cupryk,  
It's getting close. You need to assign the "ID" for the "clock" control instead of "Name" only. The object is being referred via document.getElementById().
eg:
 <input type="text" class="value" id="clock" name="clock" size="27" readonly="readonly" style="border: 0px;">
                           
0
 

Author Closing Comment

by:mathieu_cupryk
ID: 31568296
awesome
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 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