Error: Microsoft JScript runtime error: Object expected

Posted on 2008-11-09
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:


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<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 = "" />
<body MS_Positioning="GridLayout>
    <form id="form1" method=post runat="server">
    <p> The time (According to the Web Server) is:
        <%=System.DateTime.Now %>
    <p> What is the time on the Web Client?
        <input onclick ="Alert('Web Client time is now ' + new Date());"
        type=button value="Client Time" />


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)



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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">


Question by:Dovberman
    1 Comment

    Accepted Solution

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

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now