Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Adding textboxes dynamically

Reply
Thread Tools

Adding textboxes dynamically

 
 
=?Utf-8?B?QWxleCBEZW50b24=?=
Guest
Posts: n/a
 
      06-02-2006
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?
 
Reply With Quote
 
 
 
 
Mike Lowery
Guest
Posts: n/a
 
      06-02-2006
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.

"Alex Denton" <Alex http://www.velocityreviews.com/forums/(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?



 
Reply With Quote
 
 
 
 
rgiltner@gmail.com
Guest
Posts: n/a
 
      06-02-2006

Mike Lowery wrote:
> 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

 
Reply With Quote
 
=?Utf-8?B?QWxleCBEZW50b24=?=
Guest
Posts: n/a
 
      06-02-2006
Can you explain to me how I would recreate them on postback while maintaining
their values?

"(E-Mail Removed)" wrote:

>
> Mike Lowery wrote:
> > 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
>
>

 
Reply With Quote
 
Mike Lowery
Guest
Posts: n/a
 
      06-05-2006
I should have said "officially supported" in my earlier post.

See this article:
http://aspnet.4guysfromrolla.com/articles/092904-1.aspx

"Alex Denton" <Alex (E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Can you explain to me how I would recreate them on postback while maintaining
> their values?
>
> "(E-Mail Removed)" wrote:
>
>>
>> Mike Lowery wrote:
>> > 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
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you query the values of textboxes dynamically created in a Panel container?? SD ASP .Net 3 06-23-2005 10:06 PM
Get Value From Dynamically Created TextBoxes...... RC ASP .Net 1 06-07-2005 05:44 AM
How to use custom validators for dynamically genrated textboxes Charith Jayasundara via .NET 247 ASP .Net 2 03-23-2005 01:51 PM
dynamically creating textboxes based on sql records Tony ASP .Net 5 06-27-2004 08:57 PM
TextBoxes created dynamically : How to store data? Forconi Boris via .NET 247 ASP .Net 2 06-18-2004 09:09 AM



Advertisments