By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,227 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

Getting "Microsoft JScript runtime error: Object expected"

P: 3
have the following code on a page:

Expand|Select|Wrap|Line Numbers
  1.     protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         if (!IsPostBack)
  4.         {
  5.             Page.ClientScript.RegisterStartupScript(this.GetType(), "DoPreview",
  6.                     "<script language=javascript>\r\n" +
  7.                         "<!-- \r\n" +
  8.                         "function DoPreview()\r\n" +
  9.                             "{\r\n" +
  10.                                 "debugger;\r\n" +
  11.                                 "var win=null;\r\n" +
  12.                                 "var em = 'email=' + document.getElementById('ctl00_PlaceHolderMain_txtFriendsEmail').value;\r\n" +
  13.                                 "var fn = '&fname=' + document.getElementById('ctl00_PlaceHolderMain_txtFriendsFirstName').value;\r\n" +
  14.                                 "var ln = '&lname=' + document.getElementById('ctl00_PlaceHolderMain_txtFriendsLastName').value\r\n;" +
  15.                                 "var pn = '&phone=' + document.getElementById('ctl00_PlaceHolderMain_txtFriendsPhone').value;\r\n" +
  16.                                 "var a1 = '&addr1=' + document.getElementById('ctl00_PlaceHolderMain_txtFriendsAddress').value;\r\n" +
  17.                                 "var a2 = '&addr2=' + document.getElementById('ctl00_PlaceHolderMain_txtFriendsAddress2').value;\r\n" +
  18.                                 "var ct = '&city=' + document.getElementById('ctl00_PlaceHolderMain_txtFriendsCity').value;\r\n" +
  19.                                 "var st = '&state=' + document.getElementById('ctl00_PlaceHolderMain_txtFriendsState').value;\r\n" +
  20.                                 "var zp = '&zip=' + document.getElementById('ctl00_PlaceHolderMain_txtFriendsZipCode').value;\r\n" +
  21.                                 "var cy = '&cntry=' + document.getElementById('ctl00_PlaceHolderMain_txtFriendsCountry').value;\r\n" +
  22.                                 "var pm = '&pmsg=' + document.getElementById('ctl00_PlaceHolderMain_txtPersonalMessage').value;\r\n" +
  23.                                 "var url = 'DoPreview.aspx?' + em + fn + ln + pn + a1 + a2 + ct + st + zp + cy + pm;\r\n" +
  24.                                 "win = window.open(url, null, 'height=700, width=800,status= no, resizable= yes, scrollbars=yes,toolbar=no,location=no,menubar=no');\r\n" +
  25.                                 "win.focus();\r\n" +
  26.                             "}\r\n" +
  27.                             " -->\r\n" +
  28.                     "</script>\r\n", false);
  29.  
  30.             btnPreview.Attributes.Add("OnClick", "DoPreview()");
  31.  
  32.         }
  33.     }

the problem arises when I first open the window by pressing the btnPreview. The script gets called, I generate a url dynamically, adding a query string to it. The windown opens successfully the first time, however, if I close the popped up window and press that button again, it gives me the error described in the subject.

Anybody have any ideas why I might be running into this problem?

Thanks.
Jan 25 '08 #1
Share this Question
Share on Google+
7 Replies


acoder
Expert Mod 15k+
P: 16,027
What line do you get the error on?
Jan 25 '08 #2

P: 3
I get it on the following line:

btnPreview.Attributes.Add("OnClick", "DoPreview()");
Jan 25 '08 #3

acoder
Expert Mod 15k+
P: 16,027
OK, what does the code look like client-side (viewing in the browser)? You should be able to get the generated source code by selecting View Source or View Page Source.
Jan 25 '08 #4

P: 3
Aha! OK, will do....
Jan 25 '08 #5

Siddarth Tamagond
P: 1
Guys, I faced the same error, In my case no StumbleUpon tool was installed. I solved it by dissabling Javascript debugging. Go to IE browser -> Tools->Internet Options -> Advanced -> check 'Dissable script debugging(internet exploere) option. this refers to IE 7.
Apr 16 '09 #6

acoder
Expert Mod 15k+
P: 16,027
But it's a JavaScript problem, so disabling debugging won't help solve it.
Apr 16 '09 #7

P: n/a
This line should be like this:
btnPreview.Attributes.Add("OnClick", "DoPreview();");


I guess you have forgotten to add semicolon after function name.
Nov 19 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.