Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Basic Javascript error

Basic Javascript error

Scheduled Pinned Locked Moved ASP.NET
helpquestioncsharpjavascripthtml
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hardus Lombaard
    wrote on last edited by
    #1

    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>

    J D J M 4 Replies Last reply
    0
    • H Hardus Lombaard

      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>

      J Offline
      J Offline
      JHizzle
      wrote on last edited by
      #2

      Change it to OnClientClick="Hello()" OnClick set like you have it will attempt to call a server side function, i.e. your code behind. Which ain't there! Hence the error makes sense.

      1 Reply Last reply
      0
      • H Hardus Lombaard

        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>

        D Offline
        D Offline
        DaveAuld
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • H Hardus Lombaard

          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>

          J Offline
          J Offline
          Jason Vetter
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • H Hardus Lombaard

            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>

            M Offline
            M Offline
            mihsathe
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups