473,322 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how can I generate and display in a webform textboxes on the fly ???

Hello over there,
I would like to generate the textboxes on the fly depending on the number of
coulmns in a returning dataset.

I tried something like this :
TextBox temp = new TextBox();
MyPage.Controls.Add(temp);
// <-- the above one failed saying I should specify [run at server] when
this
is already a server comp

Another problem I see is that how can I specify where in the form they
should be displayed ??
Any tip will be very much appreciated,
Thank you in advace,

Genc Ymeri.

Mar 9 '06 #1
1 1284
Generating controls dynamically can be a little tricky. All ASP.NET
controls must reside in a form control. This is rendered for you
automatically (you can see it in the html markup). When you add a
control to the page, you're actually adding it at the end of the
control tree- outside of all other controls, including the form tag.

What you want to do is add a generic control- like a placeholder- to
the page, and then add your textboxes to the placeholder.

placeholder1.Controls.Add(temp);

THis will esnure you're putting it inside the form tag, and it will
also allow you to specify where they show up on the page (because
they'll appear in the placeholder).

As a general best practice, you should always set the ID property of
the textbox.

Secondly, and this is the trickiest part- when you do a postback, you
must make sure all controls are added back to the page in the Init
event. Otherwise, you'll get all sorts of wierd issues like viewstate
errors, etc. If you add three textboxes to the page, send it to the
client- it has to come back the same way. (And by come back, I mean be
constructed in the same way in the Init event).

Mar 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Scott | last post by:
I have a webform that I would like to use the autocomplete feature for all my textboxes. My textboxes are the <ASP:Textbox /> control. The only way I seem to be able to get autocomplete to work...
6
by: Tim Whelan via DotNetMonster.com | last post by:
Hi I am developing an asp.net web application using c# and having trouble trying to display integer values, that I have taken from the database, correctly on my webform textboxes. The values are...
9
by: Peter Afonin | last post by:
Hello: I need to clear all textboxes on the webform after the data has been submitted. How can I do this in one step? I found a C# code: // get a reference to your form control Control frm...
1
by: Boonaap | last post by:
Anyone an idea how to create a Hierarchical data webform? I was trying to figure it out with a datagrid but anyone a better idea? should be C# thx
0
by: Solitus | last post by:
I have a difficult scenario here. Previously I have tried to post something similar here, unfortunately I got no solution. For simplicity I have created something simple to simulate my problem. I...
4
by: WB | last post by:
Hi, How can I generate web controls such as textboxes and drop-menus on the fly? My web application allows users to fill out PDF forms online. There are many PDF forms, and my application...
1
by: Marc Hoeijmans | last post by:
Hello, Who has a fast and easy solution for displaying an RFT-tekst (stored in a Sql Server databasae) in a webform? Thanks, Marc
1
by: Sirisha | last post by:
Hi, I want javascript for displaying multiple textboxes dynamically. ADD-this is button. if i click button first time it will display 1 textbox and if i click 2nd time it will display another...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a webform with several entry boxes and the user enters numbers in each box. I keep a running total (just adds all of the entries together) but am posting back to the server to do this. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.