Link to home
Start Free TrialLog in
Avatar of Dovberman
DovbermanFlag for United States of America

asked on

Error: Microsoft JScript runtime error: Object expected

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,




ASKER CERTIFIED SOLUTION
Avatar of Dovberman
Dovberman
Flag of United States of America 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