[英]How to take textbox value from an asp.net form to a classes in vb.net code behind
I'm new in Vb.net and try to learn how to program,but i stuck on this stages. 我是Vb.net的新手,尝试学习如何编程,但是我停留在这个阶段。
I create a new sub and declare it in 1 form 我创建一个新的子并以1种形式声明
Public Class WebForm5
Public Sub info()
Dim x As String
Dim y As String
Dim z As String
x = txtbookn.Text
y = txtqua.Text.ToString
z = txtpri.Text.ToString
End Sub
End Class
and i try to pass it to another classes which in 我尝试将其传递给另一个类
Public Class Product
Public Sub New()
Me.Book_Name = (value for x)
Me.UnitPrice =(value for y)
Me.quantty=(value for z)
End Sub
End Class
Pass it in the constructor 将其传递给构造函数
Public Class Product
Public Sub New(x as String, y as String, z As String)
Me.Book_Name = x
Me.UnitPrice = y
Me.quantty = z
End Sub
End Class
Then in your page you can call it as 然后,您可以在页面中将其称为
Dim MyProduct as Product = New Product(txtbookn.Text, txtqua.Text, txtpri.Text)
Your x, y, and z variables are not in the scope of the New()
sub. 您的x,y和z变量不在
New()
子级的范围内。 If you want them to be accessible you either have to pass them as parameters, or they need to be defined outside of both classes. 如果希望它们可访问,则必须将它们作为参数传递,或者需要在两个类之外定义它们。 Right now they only exist in
info()
. 现在它们仅存在于
info()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.