[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


javascript "object expected" error calling external script from modal dialog

Posted on 2004-11-14
Medium Priority
Last Modified: 2011-09-20

I have a password change dialog made of 2 Labels, 2 TextBoxes and 2 Buttons, which I display using showModalDialog.

Here's the Page_Load

            private void Page_Load(object sender, System.EventArgs e)
                  sesh = HttpContext.Current.Session;
                  this.RegisterStartupScript("validatePassword", "<script type=\"text/javascript\" src=\"./validatePassword.js\"/>");

                  btnPwdOk.Attributes["onclick"] = string.Format("validatePassword('{0}', '{1}'); return false;", txtPwd1.ClientID, txtPwd2.ClientID);
                  btnPwdCancel.Attributes["onclick"] = "window.close(); return false";

Here's the validatePassword.js

function validatePassword(id1, id2)
      ctl1 = document.getElementById(id1);
      ctl2 = document.getElementById(id2);
      if (ctl1.value == ctl2.value)
            window.returnValue = ctl1.value;
            alert('Passwords do not match');

The problem is when I click on the OK button in the password dialog, I get this error:

Microsoft JScript runtime error: Object expected.

VS.NET then displays what I assume is the same as I'd get from "View Source" if right click actually worked on modals (anyway of enabling that btw?).  I can see that the script is registered and that the onclick attribute is set.  This is an extract:

<input type="submit" name="btnPwdOk" value="OK" id="btnPwdOk" onclick="validatePassword('txtPwd1', 'txtPwd2'); return false;"/>

<script type="text/javascript" src="./validatePassword.js"/>

I registered the script to display the modal in exactly the same and it works so I don't understand what I'm doing wrong.  

Thanks for any help,

Question by:datamobility
LVL 25

Expert Comment

ID: 12579552
guess it shud be this way
  ctl1 = document.getElementById('id1');
     ctl2 = document.getElementById('id2');
LVL 25

Accepted Solution

devic earned 2000 total points
ID: 12579598
<script type="text/javascript" src="./validatePassword.js"/>

should have closed tag:
<script type="text/javascript" src="./validatePassword.js"/></script>
LVL 21

Expert Comment

ID: 12580911
if you are using .net 2003 you can find out which part of the javascript went wrong

IE ->Tools -> Internet Options -> Advanced -> Browsing

Uncheck "Disable Script Debugging"

So next time the error pops up you can debug it and find out which part went wrong.


Author Comment

ID: 12582458
> [devic] you chould have closed tag

Thank you for your response.  I made the change to my Page_Load and it now works but I am confused.  The popup form is displayed by another external script popupModel.js.  This script is registered using the same implicit tag-close:

<script type="text/javascript" src="modalPopup.js"/>  (note the slash before the closing angle bracket).

I was using exactly the same syntax for validatePassword but it doesn't work without the explicit closing tag.

Why does it work for one and not the other?  What is the difference in the way pages are loaded for modal dialogs?

LVL 25

Assisted Solution

devic earned 2000 total points
ID: 12584600
datamobility, I'm not sure for aspx syntax, need learn it too :)
but anyway, if your aspx is ready on server, it sends to client plain html and in this html must be the closing tag </script>

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

873 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