p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 (http://p2p.wrox.com/forumdisplay.php?f=226)
-   -   Chapter 17 First Try It Out (http://p2p.wrox.com/showthread.php?t=41343)

paloyme April 17th, 2006 04:44 AM

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>




bnews987 April 17th, 2006 07:55 PM

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


paloyme April 17th, 2006 08:07 PM

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

bnews987 April 17th, 2006 08:19 PM

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.


paloyme April 17th, 2006 08:30 PM

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...


bnews987 April 17th, 2006 08:36 PM

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


paloyme April 17th, 2006 08:40 PM

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

Thanks Bryan
Emmett


DaveyDoCode August 23rd, 2006 11:14 AM

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.


All times are GMT -4. The time now is 06:13 AM.

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