Solved

i need to implement javascript function in my ascx page.

Posted on 2009-04-08
4
449 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 500 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

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

690 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