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.
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
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="true" debug="true" language="vb" Codebehind="age.aspx.vb"%>
<HTML>
<body>
<h1>If You Were a Dog</h1>
<form id="frmDog" method="post" runat="server">
How old are you?<br>
<asp:textbox id="txtAge" Runat="server"></asp:textbox>
<asp:button id="cmdOK" onclick="OKButton_Click" Runat="server" Text="OK" Width="56px"></asp:button><br>
<asp:RequiredFieldValidator ControlToValidate="age" Runat="server" id="rfv_txtAge">Please enter your age.</asp:RequiredFieldValidator><br>
<asp:Label ID="lblAnswer" Runat="server" />
</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 = "22"
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 = "If you were a dog, you'd be " & DogAge & " years old."
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