![](/img/trans.png)
[英]Read asp.net textbox text using variable for name in VB.Net code behind
[英]How to take textbox value from an asp.net form to a classes in vb.net code behind
我是Vb.net的新手,嘗試學習如何編程,但是我停留在這個階段。
我創建一個新的子並以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
我嘗試將其傳遞給另一個類
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
將其傳遞給構造函數
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
然后,您可以在頁面中將其稱為
Dim MyProduct as Product = New Product(txtbookn.Text, txtqua.Text, txtpri.Text)
您的x,y和z變量不在New()
子級的范圍內。 如果希望它們可訪問,則必須將它們作為參數傳遞,或者需要在兩個類之外定義它們。 現在它們僅存在於info()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.