Click here to Skip to main content
12,818,964 members (29,957 online)
Rate this:
Please Sign up or sign in to vote.
See more: Javascript

I have a button control as

<asp:Button runat="server" ID="btn" Text="OK" Width="100PX"  OnClientClick="return changeMessage();"/>
in aspx page.

In head section of page add a external js file using,

<script language="javascript" type="text/javascript" src="../Script/Map.js"></script>

Map.js content as below,


//Function displays the google map
function initialize() {
    var mapOptions = {
        zoom: 6,
        center: new google.maps.LatLng(8.558058925477096, 76.87785568237302),
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        navigationControl: true,
        style: google.maps.NavigationControlStyle.ZOOM_PAN
        scaleControl: true,
        DoubleClickZoom: true,
        draggable: true,
        streetViewControl: true,
        draggableCursor: 'pointer'

    map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
    //document.getElementById('messageDisplay').style.visibility = "hidden";

//Function handle the click event
function route() {


Then, in aspx page i call function 'route()' in Map.js inside a <script> tag as below


<script language="javascript" type="text/javascript">

    function changeMessage() {

        if (document.getElementById("MainContent_btn").value == "OK") {
            document.getElementById("MainContent_messageLabel").innerHTML = "Click START to start drawing route";
            document.getElementById("MainContent_routetxt").style.visibility = "hidden";
            document.getElementById("MainContent_btn").value = "START";
            return false;

        //Calling route() in Map.js

        if (document.getElementById("MainContent_btn").value == "START") {



But it give error as ,
Microsoft JScript runtime error: Object expected.

what is wrong in code?..
Posted 16-Oct-12 21:18pm
Updated 16-Oct-12 21:22pm
Arunprasath Natarajan 20-Oct-12 7:32am
I guess still few more codes are missing. Kindly provide the same.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 17 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100