Click here to Skip to main content
13,087,566 members (79,480 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi Friends,

need a help regarding an assignment. An .aspx page with a static textbox and a button named "Generate". we have to enter a number in the textbox (say 4) then on the Generate button click four(4) dynamic dropdownlist are created and a button named "ADD" is also created. The first dynamic dropdown contains number 1 to 10 and second dynamic dropdown contains 10 to 20 and so on... On clicking the dynamically generated button "ADD" button the selected values on the four dynamically created dropdownlist will added and shown in another dynamically created label and the dropdown should contain the selected values respectively without any javascript or jquery. basically its somewhat related to page lifecycle and viewstate. Can anybody please help?

Thanking You all friends. Looking for your kind help on the issue.
Posted 19-Sep-12 8:17am
Updated 19-Sep-12 9:04am
Wes Aday104.2K
Wes Aday 19-Sep-12 14:25pm
Okay and what specific issue are you having trouble with? What have you tried?
Sandeep Mewara 19-Sep-12 15:01pm
It's a repost! I replied him today only.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can definitely achieve this without using javascript or jquery. Here, the major problem is that you loose the dynamically created UI or the values on the post back of your "ADD" button click. The trick is to recreate your UI on postbacks.

1. Keep all your dynamic UI generation in one single method, say CreateDynamicUI()

2. In your CreateDynamicUI() ensure that you keep track of all the UI elements and assign unique IDs.

3. In-order to recreate UI on every postback, call CreateDynamicUI() in the Page_Load() of your aspx

4. In the "ADD" button click event, do a FindControl to get handles to the dynamically created elements.

I recommend to add all the dynamic content to one single parent control such as a panel or a table in-order to make the parsing easy.
Espen Harlinn 20-Sep-12 4:16am
Good points :-D
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I replied you today:[^]

Why a repost? Did you try it? Please try and post specific issue.
1. Define a GENERATE Button click handler X
2. In X, get the number provided in Textbox (say y)
3. Define a counter(say z). Set it to one.
4. Code a for loop from zero to y-1 (loop runs y times)
5. Create a dropdownlist inside the loop using new.

  • Provide ID

  • Define a datasource - a list

  • Populate list with fixed 10 numbers starting from z. for first loop z goes from 1 to 10, next 11-20...

  • Bind the datasource to dropdonw

  • Add the dropdown to the defined panel/placeholder in UI

6. Once for loop ends, create a button (A), define click event and add that too the defined panel/placeholder in UI.
7. for click event of A, do your manipulations as per need.

_Amy 19-Sep-12 15:44pm
My +5! Good explanation. :)
Sandeep Mewara 19-Sep-12 16:34pm
Espen Harlinn 20-Sep-12 4:15am
Sandeep Mewara 20-Sep-12 4:54am
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Sandeep is already given the steps to create and manage Dynamic Asp.Net controls. If you need little more help or guideline while creating the controls then refer the links for similar articles:
Dynamically Created Controls in ASP.NET[^]
Working with Dynamically Created Controls[^]
Dynamically Created Controls in ASP.NET[^]
Creating ASP.NET Controls Dynamically[^]

Espen Harlinn 20-Sep-12 4:16am
Nice links :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 19 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100