Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 May 30th, 2006, 12:12 AM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sramesh
Default Client Side Script Not Working

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

<!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>Untitled Page</title>

</head>
<body>
<script type ="text/javascript" language="javascript">
    function sayHi() {
        alert("Hi")}

</script>
    <form id="form1" runat="server" >
    <div>
        <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 239px; position: absolute;
            top: 44px" OnTextChanged ="sayHi();" AutoPostBack ="false" ></asp:TextBox>

        <asp:Button ID="Button1" runat="server" Style="z-index: 101; left: 157px; position: absolute;
            top: 47px" Text="Button" />
        <asp:Button ID="Button2" runat="server" Style="z-index: 102; left: 67px; position: absolute;
            top: 77px" Text="Button" />
        &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp;
        <input id="Text1" style="z-index: 103; left: 0px; position: absolute; top: 0px" type="text" onclick="return Text1_onclick()" />

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

This is my asp page. after build i got this errors

Error 1 'sayHi' is not a member of 'ASP.test_aspx'. \\itserver\Final Latest\Asp Booking\Test.aspx 18
Error 2 Character is not valid. \\itserver\Final Latest\Asp Booking\Test.aspx 18

Whats wrong with me?

Thanks
S. Ramesh


 
Old May 30th, 2006, 02:06 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi S. Ramesh,

Take a look at this: OnTextChanged ="sayHi();"

You're mixing up client side and server side stuff. OnTextChanged is a server side event that fires at the server when the text in the text box has changed. However, sayHi is a client side function. The compiler tries to find a server side method called sayHi which doesn't exist, hence the error you get.

There are a few ways to fix this:

1. Change OnTextChanged to onchange. onchange is a client side HTML attribute that causes a client side function to be called when the text box is changed. .NET will see that onchange is not a server side event, so it won't look for sayHi.

2. Alternatively, you can manually add the onchange behavior to the text box in the Page_Load event:

TextBox1.Attributes.Add("onchange", "sayHi();")

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old July 30th, 2007, 03:40 PM
Registered User
 
Join Date: Nov 2006
Location: Oldsmar, FL, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar:

Excellent solution - I searched for an hour for a nearly identical problem and your advice was dead-on. Thanks!

Anton

 
Old August 2nd, 2007, 03:56 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Anton,

You're welcome.....

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Client Side Script not working in DNN rpdrake BOOK: Professional DotNetNuke ASP.NET Portals ISBN: 0-7645-9563-6 2 February 27th, 2009 03:06 PM
Problem with client side script cschng Classic ASP Basics 2 May 23rd, 2005 12:43 AM
please help ping with client side script nlicata VBScript 0 June 10th, 2004 01:44 AM





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