Adding textboxes dynamically

G

Guest

Okay, here's my problem:

I need to populate different fields in an HTML table with TextBoxes. For
example, if I had 3 columns "Name", "Address", and "City"; I need to have a
TextBox in all of the Address fields. This is basically the code that I used.

<script language="VB" runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Label1.Text &= "<td align=left><input type=""text"" id=""txt"
& _
Database.ReadField("ID") & _
""" runat=server value=""" & _
Database.ReadField("Address") & """></td>"
End Sub

Sub Update_Click(Sender As Object, E As EventArgs)
Dim dba As DatabaseDLL = New DatabaseDLL
dba.LoadDB_SQL(Server.MapPath("address.mdb"), False, sql)

Do While Not dba.EOF
strRead = Request.Form("txt" & dba.ReadField("ID"))
If strRead <> "" Then
dba.EditField("JobCost", strRead)
dba.Update()
End If

dba.MoveNext()
Loop

dba.CloseDB()
End Sub
</script>

<form runat="server">

<asp:label id="Label1" runat="server">
Edit Subtotals:<br><br>
<a href="view_all_estimate.aspx">Back to Standard View</a><br><br>
</asp:label>

<input type="submit" runat="server" id="cmdSubmit"
onServerClick="Update_Click" value="Update Material Costs">
</form>


But when I press Submit, it obviously does not pick up those TextBoxes that
I added at runtime. How am I supposed to do this?
 
M

Mike Lowery

So you're creating a table using the text of a Label object? I don't think
that's supported...

Look at using Controls.Add.LiteralControl. You should add the table to your
form this way, or even create a table object first and add that.

Dynamically added controls are a PIA however--you have to recreate them on
postback or ASP.Net won't see them. This can get confusing/complicated quickly.
 
R

rgiltner

Mike said:
So you're creating a table using the text of a Label object? I don't think
that's supported...
Heck yeah its supported. Its a horrible way of doing things, but I've
built an entire navigable calendar inside the text property of a label.

But yes, literals are the way to go here.

Tex
 
G

Guest

Can you explain to me how I would recreate them on postback while maintaining
their values?
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top