Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 18th, 2009, 10:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default 'self' is not a member of 'ASP.frmeditresponse_aspx'?

Onload='self.focus();" works on other pages in this app, but throws this error on this page in Visual Studio. It's a pretty simple page, and nothing obvious jumps out at me as being different between this page and others, so I am stumped. Any clues for the clueless?

Code:
 
<%
Code:
@PageLanguage="VB"AutoEventWireup="false"CodeFile="frmEditResponse.aspx.vb"Inherits="Surveys.frmEditResponse" %>
<!doctypehtmlpublic"-//W3C//DTD HTML 4.0 Transitional//EN">
 <htmlxmlns='http://www.w3.org/1999/xhtml'xml:lang='en'lang='en'>
  <headrunat='server'>
   <titleid='ttlTitle'>Surveyor VIII - Result Editor</title>
   <metacontent='Microsoft Visual Studio.NET 7.0'name='GENERATOR'> 
   <metacontent='Visual Basic 7.0'name='CODE_LANGUAGE'>
   <metacontent='JavaScript'name='vs_defaultClientScript'>
   <metacontent='http://schemas.microsoft.com/intellisense/ie5'name='vs_targetSchema'>
  </head>
  <bodyonload='self.focus();'id='bdySurvey'runat='server'style="text-align: center">
   <formid='frmSurvey'name='frmSurvey'method='post'runat='server'>
    <divid='divMsg'runat='server'style="font-weight:bold; color:red"></div>
    <spanid='spnBody'style='width:100%; text-align:center'runat='server'onKeyPress="CancelEnter();"></span><!-- spnBody -->
    <asp:HiddenFieldID="fldNumberFields"runat="server"Value="1"/>

    <asp:ButtonID="btnSave"runat="server"Font-Bold="True"Text="Save Answer to Selected Results"/>
    <divstyle='width:100%; text-align:center'>
     <imgalt='Surveyor Logo'src='Backgrounds\Surveyor Logo.GIF'>
    </div>
    <spanid='spnScripts'style='width:100%; text-align:center'runat='server'></span><!-- spnScripts -->
   </form>
  </body>
</html>

 
Old February 18th, 2009, 04:56 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

What happens to all your space characters when you post????

Anyway...

It looks to me like the SERVER-side code is giving that error, no??? Because you made the <BODY> have RUNAT=SERVER?

And why the commentary about JavaScript vs. VBScript when that code is clearly JavaScript???
Code:
<body onload='self.focus();' ...>
The trailing semicolon there says this MUST be JavaScript.

Same thing, for example, where you have
Code:
onKeyPress="CancelEnter();"


I mean, I don't care which you use, but *THIS* page is clearly using JavaScript.

.
 
Old February 18th, 2009, 05:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Wink

> What happens to all your space characters when you post????

Not sure why that's an issue, but as far as I know, they come across just fine. I certainly wasn't getting any errors prior to adding this "simple" script.

> It looks to me like the SERVER-side code is giving that error, no??? Because you made the <BODY> have RUNAT=SERVER?

The error on this specific page is being displayed in VISUAL STUDIO. It's preventing compilation, so I would think the server isn't involved at this point, but stranger things have happened (we are talking MS here).

> And why the commentary about JavaScript vs. VBScript when that code is clearly JavaScript???

P2P apparently applied my standard sig. Had I been paying more attention when I posted it, I'd have turned the SIG off. I have done so in this reply!

JS is sometimes a necessary evil for lack of decent VBS examples.
 
Old February 18th, 2009, 06:37 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
The error on this specific page is being displayed in VISUAL STUDIO.


All the more reason for me to suspect that it is thinking that it needs to "handle" that onload server-side. VS in general doesn't concern itself with browser-side code.

Okay...you've got me curious...now I have to go try it... Hang on...

YEP! That is *EXACTLY* it!

I first created an ASP.NET page with just
Code:
<body onload="self.focus( );">
and it compiles just fine. Then I changed to
Code:
<body onload="self.focus( );" runat="server">
and VWD had a *FIT*!

I was using Visual Web Developer 2005 Express, so not surprising I didn't get same error message you did. But I certainly got 2 syntax errors just because of the runat=server !!



 
Old February 19th, 2009, 09:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

What a comedy of errors this thread has been!

First, you are right, it was the runat="server" on the body that was causing the problem. I removed the reference and the page now works like all the others. No clue how it crept in there nor how I overlooked that when comparing it to the other pages, but I can't balme VS for that!

But to be sure I understand the problem and avoid this in the future, the issue seems to be that it was trying to run JS on the server rather than the client and it had no reference there for self which is only available in the browser, right? I have input fields on another page defined as runat="server" with onclick javascripts that are expected to run on the client without any trouble, so it seems inconsistent to me for runat="server" to imply server based scripts in the body tag but client based scripts on an input tag. As you lit the path for me, though, I was able to find something related to this elsewhere:

http://connect.microsoft.com/VisualS...dbackID=104654

As to other errors of misperception, I completely misunderstood your question regarding what happened to the spaces when I posted. I assumed you were talking about how the page I requested assistance with was posting spaces, as though you saw something else wrong with my page that would prevent it from posting spaces on top of the problem I was already having with this runat issue. I now see that you meant what happened to the spaces in the HTML I posted here! I am not usually so thick. I have no idea what happened to them. As I recall they were there when I pasted the code. I certainly didn't take them out, as that would only hamper any attempts to figure out WTF was wrong with my code. Very strange!

Thanks for once again coming to the resuce, Old Pedant!
 
Old February 19th, 2009, 09:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

And I fixed .my Sig. Sorry for any further confusion it may have caused, particularly with the uninterpretted embedded HTML.
 
Old February 19th, 2009, 04:38 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
But to be sure I understand the problem and avoid this in the future, the issue seems to be that it was trying to run JS on the server rather than the client
No, I don't think so. I think the fact that you coded runat=server told VS that all of the ONXXX event handlers were now *server side* event handlers.

After all, if you code
Code:
<asp:button runat=server onclick="handleButtonClick" .../>
that is telling ASP.NET (and VS) that the onclick handler will be taken care of via a postback to the server (and of course the handler will be written in VB.NET code, given the rest of your page). You have to explicitly use event handlers such as onClientClick=... to instead force ASP.NET to allow you to specify client-side JS handlers. Or you add attributes to the fields.

So I think that what happens here is that with <body runat=server onload="self.close();"> VS believes that it should be supplying a server-side method for the body.onload event. And then it tries to parse "self.focus();" as VB.NET code, and of course it won't even pass syntax much less semantics. I suspect that if you did put something in there that passed syntax you'd get a different message...probably one telling you that you didn't have a server-side event handler that matched the specification.

More than likely, ONLOAD isn't even a valid event for <BODY>, server-side (how could it be? the page loads and then immediately goes back to the server to handle the onload??? I don't think so!), but the parser didn't get that far. It just choked on the invalid VB code. Not the cleverest thing in the world--I think it should have just said "You can't use ONLOAD with a server-side control"--but at least understandable.
 
Old February 19th, 2009, 04:42 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

And sorry about the confusion over the "spaces". I should have been clearer. After all, when you look at your own code without the spaces, you probably don't really notice the lack. Just something weird about the way this supposedly smart editor does pasting, I guess.
 
Old February 19th, 2009, 05:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

That's just bizarre and counter-intuitive - if the condition makes no sense, why even allow it, much less return such an obscure error message (which is just so like JS with its ubiquitous object undefined error!) What is so sad about this is how much time was wasted trying to do something that should not only have been simple, but default behavior. I was just trying to set up the pages so that as users changed between them, clicking links to re-open an already opened page would cause that page to come to the front of the stack of windows (which was not happening much to the consternation of my denser users who simply thought the links were not working because nothing appeared while the pages were refreshing in the background).

In any case, your solution worked so I'll take your word for it on the explanation, although I did have one instance where I was referencing the BODY tag from server code AND I thought I needed the self.focus() on load, too. As that's clearly an impossible combination, I left the RUNAT=SERVER on the body, and moved the self.focus to a simple JS that runs every time the page is refreshed. It wasn't as important it happen in the onload as it was in these other pages, where I only wanted this to happen when re-opening a page that was already open in another window. Even trying to trap a postback in scripting was unnecesarily complex. I had to add code to the page_load to write a variable to the Form so I could check it for a post back condition. Would it REALLY have been so difficult to include isPostBack in these crummy scripting "languages"? I know, I'm preaching to the choir!

Anyway, thanks again!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi.. new member here.. renai C# 1 August 26th, 2007 11:20 AM
Need an ASP script for Member reg. & Logon CSUjr Classic ASP Basics 1 October 16th, 2006 08:01 AM
Hello from a new member aehb C# 0 March 10th, 2005 05:51 PM
I'm a new member.. kiddyboy Visual C++ 1 August 12th, 2003 07:21 AM
Member kilika Forum and Wrox.com Feedback 6 July 18th, 2003 12:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.