Link to home
Start Free TrialLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

i need to implement javascript function in my ascx page.

<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

Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

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">
....






Avatar of mathieu_cupryk

ASKER

 '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

ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
awesome