Basic Javascript error
-
I am quite new to Javascript and this question probably would seem very basic, but I am really stuck. I have a button. When I click it, the Javascript should cause an alert to display "hello" to the screen. When I build the project I get the error: 'ASP.default_aspx' does not contain a definition for 'Hello' and no extension method 'Hello' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?) Aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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>Test</title>
<script type="text/javascript">
function Hello() {
alert("hello");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onClick="Hello()"/>
</div>
</form>
</body>
</html> -
I am quite new to Javascript and this question probably would seem very basic, but I am really stuck. I have a button. When I click it, the Javascript should cause an alert to display "hello" to the screen. When I build the project I get the error: 'ASP.default_aspx' does not contain a definition for 'Hello' and no extension method 'Hello' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?) Aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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>Test</title>
<script type="text/javascript">
function Hello() {
alert("hello");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onClick="Hello()"/>
</div>
</form>
</body>
</html> -
I am quite new to Javascript and this question probably would seem very basic, but I am really stuck. I have a button. When I click it, the Javascript should cause an alert to display "hello" to the screen. When I build the project I get the error: 'ASP.default_aspx' does not contain a definition for 'Hello' and no extension method 'Hello' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?) Aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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>Test</title>
<script type="text/javascript">
function Hello() {
alert("hello");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onClick="Hello()"/>
</div>
</form>
</body>
</html>here;
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Submit1" type="submit" value="submit" onclick="return Hello();" />
</div>
</form>
</body><script type="text/javascript" language="javascript">
function Hello()
{ alert("Hello"); }
</script>
</html>Dave Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn
Waving? dave.m.auld[at]googlewave.com -
I am quite new to Javascript and this question probably would seem very basic, but I am really stuck. I have a button. When I click it, the Javascript should cause an alert to display "hello" to the screen. When I build the project I get the error: 'ASP.default_aspx' does not contain a definition for 'Hello' and no extension method 'Hello' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?) Aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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>Test</title>
<script type="text/javascript">
function Hello() {
alert("hello");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onClick="Hello()"/>
</div>
</form>
</body>
</html>It's just the difference between using a standard html button or an asp.net server button. A button with runat="server" behaves very differently than a normal html button.
-
I am quite new to Javascript and this question probably would seem very basic, but I am really stuck. I have a button. When I click it, the Javascript should cause an alert to display "hello" to the screen. When I build the project I get the error: 'ASP.default_aspx' does not contain a definition for 'Hello' and no extension method 'Hello' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?) Aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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>Test</title>
<script type="text/javascript">
function Hello() {
alert("hello");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onClick="Hello()"/>
</div>
</form>
</body>
</html>You see this form is supposed to run on server side. So it'll try to call procedures on the server and not the client. If you want to perform this task, you have some options like: write a function in C# on server side like this public void Hello() {MessageBox.Show("Hello World")} or do not use an asp button. Use HTML button like or as said by somebody above, you can use onClientClick event handler.. Hope this will clarify all your doubts Don't forget to rate the comments