Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference a textbox by it's ID but use a variable as the ID

Status
Not open for further replies.

KidHoss

Programmer
May 22, 2000
27
US
If I had a series of textboxes like below:

Code:
<asp:textbox id=txtBox01 runat="server">
<asp:textbox id=txtBox02 runat="server">
<asp:textbox id=txtBox03 runat="server">
<asp:textbox id=txtBox04 runat="server">
<asp:textbox id=txtBox05 runat="server">

If I wanted to write a For/Next loop to get the ".TEXT" information out of these boxes, could I create a variable to refernce the id value? Is there some way to add the loop counter to the variable in order to reference the "id"? Is this possible?

Thanks
 
try this:
<%@ debug=true%>
<script runat="server">
sub page_load
Dim Ctrl as Control

for each Ctrl in Frm.Controls
Dim TheId as String=ctype(Ctrl.id,string)
if(TheId<>"") then
if(TheId.indexOf("txtBox")<>-1) then
response.write("ASD")
end if
end if
next
end sub
</script>
<form runat="Server" id=Frm>
<asp:textbox id=txtBox01 runat="server" />
<asp:textbox id=txtBox02 runat="server" />
<asp:textbox id=txtBox03 runat="server" />
<asp:textbox id=txtBox04 runat="server" />
<asp:textbox id=txtBox05 runat="server" />
</form>

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top