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


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,

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guess it shud be this way
  ctl1 = document.getElementById('id1');
     ctl2 = document.getElementById('id2');
<script type="text/javascript" src="./validatePassword.js"/>

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

datamobilityAuthor Commented:
> [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?

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>
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.