Codebehind Events not working

M

Mike Dinnis

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
 
D

Dmitriy Lapshin [C# / .NET MVP]

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

Mike Dinnis

Ah,

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

Sorry!

<M>ike

Dmitriy Lapshin said:
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]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Mike Dinnis said:
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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top