If i have multiple textboxes with the same Id and name in a form, how to fetch there values separately in vb.net? can anyone help me? thanks in advance.
in javascript iv used fetched them like this
var b=document.getElementById('TextBox')
va开发者_StackOverflow社区r a=b.length;
for(var i=0; i<a; i++) {
var text=b[i];
alert(text)
}
You should have a seperate ID from them. How are you generating those text boxes ?
Generate the textboxes in a loop and assign them the incrementing IDs, for ex box1,box2 ....
Here is an example for vb.net
For Each oControl As Control In Page.Controls
If TypeOf oControl Is TextBox Then
Dim txtbox As TextBox = CType(oControl, TextBox)
txtbox.Text = Date.Now.ToString
End If
Next
in your case something like this assuming your textboxes ids are like txtTestTxt0, txtTestTxt1,txtTestTxt2 and so on
For x As var = 0 To Page.Controls
If Page.FindControls("txtTestTxt" & x) IsNot Nothing Then
Dim tb As TextBox = DirectCast(Page.FindControl("txtTestTxt" & x.tostring()), TextBox)
myval = tb.Text
End If
Next
精彩评论