?
Solved

Error: Microsoft JScript runtime error: Object expected

Posted on 2008-11-09
1
Medium Priority
?
1,659 Views
Last Modified: 2013-11-26
I am attempting to learn C# by using an example shown in "Beggining Visual Web rogramming in C#" by Daniel Calzzulino etc.  The example displays the time based on the Web server. When a button is clicked, the Client time is displayed.

This all works well until I click the button that is designed to display the Client time. I get the
Microsoft JScript runtime error: Object expected error on the folllowing line:
    <input onclick ="Alert('Web Client time is now ' + new Date());"
        type=button value="Client Time" />
What did I do wrong?

Here is the code:

Webform1.aspx

<%@ Page Language="C#" CodeBehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="ClockExample.WebForm1" %>

<!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 runat="server">
    <title>What Time is it</title>
    <meta name="CODE_LANGUAGE" content = "C#" />
    <meta name="vs_defaultClientScript" content = "JavaScript" />
    <meta name="vs_targetSchema" content = "http://schemas.microsoft.com/intellisence/ie5" />
</head>
<body MS_Positioning="GridLayout>
    <form id="form1" method=post runat="server">
    <p> The time (According to the Web Server) is:
        <%=System.DateTime.Now %>
    </p>
    <p> What is the time on the Web Client?
        <input onclick ="Alert('Web Client time is now ' + new Date());"
        type=button value="Client Time" />
    </p>
    </form>
</body>
</html>

Webform1.aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace ClockExample
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="ClockExample._Default" %>

<!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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    </form>
</body>
</html>

Thanks,




0
Comment
Question by:Dovberman
1 Comment
 

Accepted Solution

by:
Dovberman earned 0 total points
ID: 22916408
I found the error:

The alert object should be referenced as window.alert

    <input onclick= "window.alert('Web Client time is now ' + new Date());"
        type=button value="Client Time" />
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

839 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