473,581 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating controls dynamically based on user input

I can think of a lot of reasons why this might need to be done but as
far as I can tell it's not possible. I've been looking for a way to
add HtmlTableRows to a table using a button click for a while and it
seems it's not possible because the row that gets added with each
click won't get recreated after a post back. After all the reading it
seems that any dynamically created controls must be created in the
Init event to be recreated after postback. This I think is very
unfortionate as it makes it impossible to change the display
interactively. Can someone please verify that this really is
impossible to do?

Oct 30 '07 #1
4 2960
OK, I'll verify that you are on the right track. You will need to
recreate the number of rows you dynamically created during init. But,
once you've done that view state should be able to recreate everything
else.

"Any dynamically created controls must be created in Init to be
recreated after postback." Would be better stated, "Any dynamically
created control must be recreated in Init to have its state reset after
postback." Viewstate assumes the control object has been created, it is
just resetting the state of that object. Not, recreating the object AND
setting the state.

All you really need is a way to keep track of what you created
dynamically so that you can recreate it during init. You could do this
with a hidden field which you could get from
Request.Form["hiddenFieldNam e"] during Init.
-----Original Message-----
From: mo******@gmail. com [mailto:mo****** @gmail.com]
Posted At: Tuesday, October 30, 2007 7:44 PM
Posted To: microsoft.publi c.dotnet.framew ork.aspnet
Conversation: Creating controls dynamically based on user input
Subject: Creating controls dynamically based on user input

I can think of a lot of reasons why this might need to be done but as
far as I can tell it's not possible. I've been looking for a way to
add HtmlTableRows to a table using a button click for a while and it
seems it's not possible because the row that gets added with each
click won't get recreated after a post back. After all the reading it
seems that any dynamically created controls must be created in the
Init event to be recreated after postback. This I think is very
unfortionate as it makes it impossible to change the display
interactively. Can someone please verify that this really is
impossible to do?

Oct 31 '07 #2
I don't think you are on the right track. You shouldn't need to build any
table dynamically. Instead, you should use one of the databound controls
that produce tables, like GridView, DataList or Repeater. You need to define
a datasource that will contain items (rows) holding data that will go to the
resulting table rows. When you databind the control to the datasource, it
will build the table for you automatically. The datasource doesn't have to
be a database table. It can be any collection object, like an array etc.
Based on user input, modify the datasource object, re-bind the control and
you are done.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<mo******@gmail .comwrote in message
news:11******** **************@ d55g2000hsg.goo glegroups.com.. .
>I can think of a lot of reasons why this might need to be done but as
far as I can tell it's not possible. I've been looking for a way to
add HtmlTableRows to a table using a button click for a while and it
seems it's not possible because the row that gets added with each
click won't get recreated after a post back. After all the reading it
seems that any dynamically created controls must be created in the
Init event to be recreated after postback. This I think is very
unfortionate as it makes it impossible to change the display
interactively. Can someone please verify that this really is
impossible to do?

Oct 31 '07 #3
If I shouldn't need to create a table dynamically then how would you
create a table which will have a undetermined number of rows? Meaning
the number of rows needs to change based on what the user needs. In my
case I have to allow the user the ability to create a new row of
information based on a button click. I keep trying to think of ways
around this problem and am now thinking maybe it's possible to pre-
create my table in the Init event with more rows then will be needed,
then set all the rows except the first one to Visible=False. Then as
the user needs another row I will just make it visible. This might
work. It's a hack as it will be a problem if the user needs more rows
then were provided.

I'm also thinking maybe I can do this using pure html and the
Request.Form method to custom build what I need.

There must be some way to do this.

On Oct 31, 1:15 am, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
I don't think you are on the right track. You shouldn't need to build any
table dynamically. Instead, you should use one of the databound controls
that produce tables, like GridView, DataList or Repeater. You need to define
a datasource that will contain items (rows) holding data that will go to the
resulting table rows. When you databind the control to the datasource, it
will build the table for you automatically. The datasource doesn't have to
be a database table. It can be any collection object, like an array etc.
Based on user input, modify the datasource object, re-bind the control and
you are done.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

<mohaa...@gmail .comwrote in message

news:11******** **************@ d55g2000hsg.goo glegroups.com.. .
I can think of a lot of reasons why this might need to be done but as
far as I can tell it's not possible. I've been looking for a way to
add HtmlTableRows to a table using a button click for a while and it
seems it's not possible because the row that gets added with each
click won't get recreated after a post back. After all the reading it
seems that any dynamically created controls must be created in the
Init event to be recreated after postback. This I think is very
unfortionate as it makes it impossible to change the display
interactively. Can someone please verify that this really is
impossible to do?- Hide quoted text -

- Show quoted text -

Oct 31 '07 #4
If I shouldn't need to create a table dynamically then how would you
create a table which will have a undetermined number of rows?
The point is that you add rows to the datasource which could be as simple as
just an array or an ArrayList. Than you do something like myGrid.DataBind ()
and you get a table with as many rows as the number of items in your
datasource.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

Nov 1 '07 #5

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

Similar topics

6
5999
by: Glenn Owens | last post by:
I have an ASP.Net page on which there are serveral static controls (listboxes, radiobuttonlist and textboxes). These controls are used to create criteria from which the code-behind will dynamically create 1-n datagrids. When the Submit button is clicked I need to save (in viewstate) the contents of the criteria controls so that I can...
1
1651
by: C Downey | last post by:
I have a registration form that should load different web user controls based on the selection of a dropdown list. Basically, the user follows the following steps: 1. user comes to very basic web form, no controls loaded 2. user selects registration type (1 of 4 possible types) from a dropdown control 3. the dropdown properties are :...
2
4555
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is easy, but 1) How do I set about dynamically creating user controls (like TextBox, TextArea) --- simply Declare and initialised (new) the user...
1
3404
by: Marcus | last post by:
I have a problem maybe one of you could help me with. I've created a data entry screen with lots of dynamically-created client-side controls. I create HTML texboxes client-side by assigning a value to the td.innerHTML property. The UI is done, and I now want to post back the user's changes and update my business object in .NET. But when I...
12
3148
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without restarting the application. What I did was to create an AppDomain that loaded the plugins and everything was great, until I tried to pass...
2
1687
by: epigram | last post by:
I'm dynamically creating a number of radio buttons on my aspx page based upon data read from a db. Each radio button has autopostback turned on. I'm experiencing two problems. 1) I am reading the db, creating the radio buttons, and setting the checked property (also based upon data in the db) in Page_Load regardless of whether a postback...
5
3719
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button. When the user clicks the "Add another email" it will call a client side JavaScript function, add_email, which will dynamically add a new set of...
15
3602
by: mc | last post by:
I'm writing an app for managing Task Lists, I'm trying to add some controls to a form that I can use to link tasks, my original intention was to: - Add two list boxes, one listing "all Tasks" and the other listing "Linked Tasks", I have two buttons which in javascript move items from the first list into the second. Then when a user...
1
2300
by: hardieca | last post by:
Hi, I'm building a multi-lingual CMS. The user can add as many languages as he likes. The user will be able to create sections for different content (General, News Releases, etc...) in the db table tblSection. For each section, the user will have to input the section name for each language he is supporting in tblSectionLang. So, if the...
0
7789
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8301
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6551
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5361
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3820
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1400
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.