Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ErrMsg: OKButton_Click is not a member of ASP.age_aspx 1

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
US
I am begining to develop with ASP.Net. I am still trying to get my head around the whole concept and syntax. I have some books that help me. The ASP.Net for Dummies book does not talk about the Code Behind file. All the examples put the code directly in script tags.

In my quest to better understand the file structure in ASP.Net I moved the code from the script tags to the methods in the code behind file. Now when I execute the example I get a compile error. below is the HTML, then the VB.

Code:
<%@page explicit=&quot;true&quot; debug=&quot;true&quot; language=&quot;vb&quot; Codebehind=&quot;age.aspx.vb&quot;%>
<HTML>
	<body>
		<h1>If You Were a Dog</h1>
		<form id=&quot;frmDog&quot; method=&quot;post&quot; runat=&quot;server&quot;>
			How old are you?<br>
			<asp:textbox id=&quot;txtAge&quot; Runat=&quot;server&quot;></asp:textbox>
			<asp:button id=&quot;cmdOK&quot; onclick=&quot;OKButton_Click&quot; Runat=&quot;server&quot; Text=&quot;OK&quot; Width=&quot;56px&quot;></asp:button><br>
			<asp:RequiredFieldValidator ControlToValidate=&quot;age&quot; Runat=&quot;server&quot; id=&quot;rfv_txtAge&quot;>Please enter your age.</asp:RequiredFieldValidator><br>
			<asp:Label ID=&quot;lblAnswer&quot; Runat=&quot;server&quot; />
		</form>
	</body>
</HTML>


Public Class Age_class
    Inherits System.Web.UI.Page
    Protected WithEvents message As System.Web.UI.WebControls.Label
    Protected WithEvents txtAge As System.Web.UI.WebControls.TextBox
    Protected WithEvents rfv_txtAge As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents lblAnswer As System.Web.UI.WebControls.Label
    Protected WithEvents cmdOK As System.Web.UI.WebControls.Button
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' ispostback is used to determine whether to set default values or accept the users values
        If Not IsPostBack Then
            txtAge.Text = &quot;22&quot;
        End If
    End Sub

    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        If Page.IsValid = True Then
            Dim UserAge, DogAge As Integer

            UserAge = txtAge.Text
            DogAge = UserAge / 7
            lblAnswer.Text = &quot;If you were a dog, you'd be &quot; & DogAge & &quot; years old.&quot;
        End If
    End Sub
End Class

The error message is in line 8 of the HTML code. Here is the messaqe: 'OKButton_Click' is not a member of 'ASP.age_aspx'

Why is this error occuring?

Thank you for your assistance

Jason Meckley
Database Analyst
WITF
 
looking quickly, its right... there is no OKButton_Click in that class... I think you should change your onclick to be
Code:
onclick=&quot;cmdOK_Click&quot;
 
gagz

Thank you for the correction. After I fixed that error more came up, but I was able to debug them. One error stated that I could not call the cmdOK_Click method because it was private. I made it a public function instead and it worked fine.

Why does this function need to be public, but the page load can remain private?

Thank you for your assistance

Jason Meckley
Database Analyst
WITF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top