Access server control programatically like me.control("controlname").value

J

Joe

With asp.net 2.0 i have various textbox controls on my form. When the
user submits the form i want to do a

These are the controls:

<asp:TextBox ID="txtBook1" runat="server" CssClass="txtSmall"/>
<asp:TextBox ID="txtBook2" runat="server" CssClass="txtSmall"/>
<asp:TextBox ID="txtBook3" runat="server" CssClass="txtSmall"/>
<asp:TextBox ID="txtBook4" runat="server" CssClass="txtSmall"/>


This is the code i am trying to write:

For I = 1 to 4
Somevar(I) = me.controls("txtbook" & I)
Next

No quite sure how to do it?

Thanks in Advance
 
G

Guest

Joe,
You are so close with your code great start. I'm not sure if just case of
txtBook will make it work! But I know for a fact this works with findcontrol.

For I = 1 to 4
Somevar(I) = me.findcontrol("txtBook" & I)
Next

Maybe an old style control array would work for you. Make a function that
returns textbox, find the control, return the control, use the function as a
control array. No error checking so be carefull.

Private Function txtBook(x as integer) As textbox
Return ctype(me.FindControl("txtBook" & x),textbox)
End Function

for k = 1 to 4
txtBook(k).text = "hello world"
next

Good Luck
DWS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top