G
Guest
I have a web application that collects user input on a page. This is then
processed separately in a class. I want to return the values created in the
class to another web page. I can get this to work fine if I return the
values created in the class to the original page, but I can't get this to
work when I try with the second page.
To illustrate the problem, I have a sample pag e with 2 text boxes, a label
and a button. The user puts some numbers in each of the text boxes. When
the button is clicked, the class adds together the text box values, and the
label displays the result:
On the input page:
Dim class1 As New Class1
Dim x As Single
Dim y As Single
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
x = CSng(TextBox1.Text)
y = CSng(TextBox2.Text)
class1.DoAdd(x, y)
Label1.Text = CStr(class1.getTheAnswer)
End Sub
The class code:
Public Class Class1
Private thesum As Single
Public Sub DoAdd(ByVal x As Single, ByVal y As Single)
thesum = Val(x + y)
End Sub
Public Function getTheAnswer() As Single
getTheAnswer = thesum
End Function
End Class
If I try to, for example, change the button click event to go to a second
page and display the class.getTheAnswer on a label on it, I get an 'reference
to a non-shared member requires an object reference' error in the code:
(the second page code)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
lblTest.Text = CStr(class1.getTheAnswer)
End Sub
I presume that I am guilty of some fundamental lack of knowledge, but would
really appreciate some help with this. Thanks.
processed separately in a class. I want to return the values created in the
class to another web page. I can get this to work fine if I return the
values created in the class to the original page, but I can't get this to
work when I try with the second page.
To illustrate the problem, I have a sample pag e with 2 text boxes, a label
and a button. The user puts some numbers in each of the text boxes. When
the button is clicked, the class adds together the text box values, and the
label displays the result:
On the input page:
Dim class1 As New Class1
Dim x As Single
Dim y As Single
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
x = CSng(TextBox1.Text)
y = CSng(TextBox2.Text)
class1.DoAdd(x, y)
Label1.Text = CStr(class1.getTheAnswer)
End Sub
The class code:
Public Class Class1
Private thesum As Single
Public Sub DoAdd(ByVal x As Single, ByVal y As Single)
thesum = Val(x + y)
End Sub
Public Function getTheAnswer() As Single
getTheAnswer = thesum
End Function
End Class
If I try to, for example, change the button click event to go to a second
page and display the class.getTheAnswer on a label on it, I get an 'reference
to a non-shared member requires an object reference' error in the code:
(the second page code)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
lblTest.Text = CStr(class1.getTheAnswer)
End Sub
I presume that I am guilty of some fundamental lack of knowledge, but would
really appreciate some help with this. Thanks.