Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6
This is the forum to discuss the Wrox book Beginning Visual Basic 2005 by Thearon Willis, Bryan Newsome; ISBN: 9780764574016
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 17th, 2006, 04:44 AM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 17 First Try It Out

My page is not working properly, the Client button is not working and it generates this error

//Line 12
//Column 30
//Invalid Character
//Code 0

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>My First Page</title>
    <meta http-equiv= "content-script-type" content="text/VBScript" />
        <script language="VBscript" type="text/VBscript">
// <!CDATA[

function btnClient_onclick() {
document.getElementById("lblclient").innerText = "Changed"
document.getElementById("lblServer").innerText = "Server"

}

// ]]>
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btnServer" runat="server" Style="z-index: 104; left: 72px; position: absolute;
            top: 128px" Text="Server" />
        <asp:Label ID="lblServer" runat="server" Style="z-index: 101; left: 168px; position: absolute;
            top: 128px" Text="Server"></asp:Label>
        <asp:Label ID="lblClient" runat="server" Style="z-index: 102; left: 168px; position: absolute;
            top: 176px" Text="Client"></asp:Label>
        <input id="btnClient" style="z-index: 103; left: 72px; position: absolute; top: 176px"
            type="button" value="Client" onclick="return btnClient_onclick()" />

    </div>
    </form>
</body>
</html>



  #2 (permalink)  
Old April 17th, 2006, 07:55 PM
Wrox Author
Points: 333, Level: 6
Points: 333, Level: 6 Points: 333, Level: 6 Points: 333, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2006
Location: , , .
Posts: 91
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You can use Javascript as you have written, but you need to change one line to set the correct language in that case.

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


Or you can make the 2 changes below to use VBScript. Replace your code with this code that is VBScript.

**** 1 START ******
<script language="VBscript" type="text/VBscript">
Sub btnClient_onclick()
  document.getElementById("lblclient").innerText = "Changed"
  document.getElementById("lblServer").innerText = "Server"
End Sub
</script>
**** 1 END ******


**** 2 START ******
<input id="btnClient" style="z-index: 103; left: 72px; position: absolute; top: 176px" type="button" value="Client" onclick="btnClient_onclick()" />
**** 2 END ******

Hope this helps,

Bryan

  #3 (permalink)  
Old April 17th, 2006, 08:07 PM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well that took care of the problem, I had no idea that "function" and "return" only works for javascipt

all this trouble just because i could not find that DefaultClientScript property under documents, I wonder what's wrong with my VB?

thanks for your help Bryan
  #4 (permalink)  
Old April 17th, 2006, 08:19 PM
Wrox Author
Points: 333, Level: 6
Points: 333, Level: 6 Points: 333, Level: 6 Points: 333, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2006
Location: , , .
Posts: 91
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Glad it works. I still have not found the solution to the defaultClientScript. I will spend some more time on that since it looks like many readers will have an issue with that being missing in the release version of VB 2005.

By the way, function will work for both languages. I used sub since this procedure does not return a value. You could changed the sub to function and added an end function instead of end sub for VB syntax and it would still work.

  #5 (permalink)  
Old April 17th, 2006, 08:30 PM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

oh I see, hehehe I really am a newbie at VB, just started last week. I noticed that the "return" value is omitted at the *****2 Start***** section. Like you said, is this because there is no value to return? This probably caused the error in the first place.... hmmm... VB automatically created the "function" method after I selected the "btnClient" and "onclick" from the dropdown list. I guess VB is not that perfect at predicting correct code structure...

  #6 (permalink)  
Old April 17th, 2006, 08:36 PM
Wrox Author
Points: 333, Level: 6
Points: 333, Level: 6 Points: 333, Level: 6 Points: 333, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2006
Location: , , .
Posts: 91
Thanks: 0
Thanked 5 Times in 5 Posts
Default

It looks like Visual Studio entered JavaScript at first. Take your original code and just change the language to javascript in the attributes of the script tag. Then the function and the return will work. Return in the button event is needed for javascript but causes an error for vbscript. Happy Coding! Bryan

  #7 (permalink)  
Old April 17th, 2006, 08:40 PM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That sure explains a lot:) ... Mmmmmm Coding Knowledge..... yummy... hehehe

Thanks Bryan
Emmett

  #8 (permalink)  
Old August 23rd, 2006, 11:14 AM
Registered User
 
Join Date: Aug 2006
Location: omaha, ne, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've got a problem with this first sample as well. The client button doesn't work. This little tidbit:

document.getElementById("lblClient").innerText = "Changed"

didn't display the "innertext" option as I was typing it in.

Here is all the code:


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="Server">
<title>My First .Net Page</title>
<meta content="text/VBScript" http-equiv="content-script-type" />
<script language="VBscript" type="text/VBscript">

// <!CDATA[

function btnClient_onclick() {
document.getElementById("lblClient").innerText = "Changed"
document.getElementById("lblServer").innerText = "Server"
}

// ]]>
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btnServer" runat="server" Text="Server" style="z-index: 100; left: 16px; position: absolute; top: 168px" Height="24px" Width="64px" />
        <asp:Label ID="lblServer" runat="server" Text="Server" style="z-index: 101; left: 104px; position: absolute; top: 168px" Width="88px"></asp:Label>
        <input id="btnClient" style="z-index: 103; left: 16px; position: absolute; top: 200px; width: 64px;"
            type="button" value="Client" onclick= "return btnClient_onclick()" />
        <asp:Label ID="lblClient" runat="server" Text="Client" style="z-index: 104; left: 104px; position: absolute; top: 200px" Width="88px"></asp:Label>

        </div>
    </form>
</body>
</html>

Thanks in advance for any help.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Errata Chapter 17 sahyouni ASP.NET 2.0 Professional 1 July 9th, 2009 06:07 AM
Chapter 17 problem twr195 BOOK: Beginning ASP 3.0 0 May 25th, 2006 09:34 AM
Chapter 17 first Try It Out paloyme Visual Basic 2005 Basics 0 April 17th, 2006 04:34 AM
Chapter 17 Gaby BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 3 September 8th, 2005 11:50 AM



All times are GMT -4. The time now is 04:53 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.