简体   繁体   中英

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.

I create a new sub and declare it in 1 form

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. 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() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM