Codebehind Events not working

Discussion in 'ASP .Net' started by Mike Dinnis, Nov 18, 2003.

  1. Mike Dinnis

    Mike Dinnis Guest

    I know it's probably my code but I don't seem to be able to get OnClick
    events to tie up. The OnLoad and other standard events will fire but not a
    button onclick. Here's a sample of what i'm trying to do..

    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="newhist.aspx.vb"
    Inherits="History.newhist"%>
    <HTML>
    <HEAD>
    <LINK href="Styles.css" type="text/css" rel="STYLESHEET">
    </HEAD>
    <BODY>
    <form id="frmNewHistory" method="post" runat="server">
    <asp:TextBox id="txtWork" runat="server" Width="240px"
    Height="112px"></asp:TextBox>
    <asp:Button id="cmdEnter" runat="server" Text="Enter"
    OnClick="EnterData"></asp:Button>
    </form>
    </BODY>
    </HTML>

    using the code behind of...

    Public Class newhist
    Inherits System.Web.UI.Page
    Protected WithEvents txtWork As System.Web.UI.WebControls.TextBox
    Protected WithEvents cmdEnter As System.Web.UI.WebControls.Button

    Public Sub EnterData(ByVal Sender As Object, ByVal e As EventArgs)
    Handles cmdEnter.Click
    Dim obHistory As New History.History
    obHistory.AddHistory(txtWork.Text)
    txtWork.Text = "Done"
    End Sub
    End Class

    The error I get is "Compiler Error Message: BC30456: 'EnterData' is not a
    member of 'ASP.newhist_aspx'."

    Is there anything obvious that i'm doing wrong?

    Cheers,

    <M>ike
     
    Mike Dinnis, Nov 18, 2003
    #1
    1. Advertisements

  2. Mike,

    Seems you are missing a namespace declaration in the code behind. May be the
    "History" namespace is assumed by default in the VB ASP .NET project, but
    you'd better check that.

    I also have a feeling that since you've already specified the Handles
    modifier in the code-behind, you might want to try to remove the "OnClick"
    attribute in the ASPX file.
     
    Dmitriy Lapshin [C# / .NET MVP], Nov 18, 2003
    #2
    1. Advertisements

  3. Mike Dinnis

    Mike Dinnis Guest

    Ah,

    Found it. I hadn't compiled the code sfter making the amendments.

    Sorry!

    <M>ike

     
    Mike Dinnis, Nov 19, 2003
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.