Click here to Skip to main content
Sign Up to vote bad
good
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:17
Edited 19 Sep '12 - 9:04
Wes Aday59.2K

Comments
Wes Aday - 19 Sep '12 - 14:25
Okay and what specific issue are you having trouble with? What have you tried?
Sandeep Mewara - 19 Sep '12 - 15:01
It's a repost! I replied him today only.

3 solutions

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.
  Permalink  
Comments
Espen Harlinn - 20 Sep '12 - 4:16
Good points :-D
I replied you today: http://www.codeproject.com/Messages/4371298/Re-Dynamic-Control-Help.aspx[^]
 
Why a repost? Did you try it? Please try and post specific issue.
Steps:
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.
 
Try!
  Permalink  
Comments
_Amy - 19 Sep '12 - 15:44
My +5! Good explanation. :)
Sandeep Mewara - 19 Sep '12 - 16:34
Thanks!
Espen Harlinn - 20 Sep '12 - 4:15
5'ed!
Sandeep Mewara - 20 Sep '12 - 4:54
Thanks.
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[^]
 

--Amit
  Permalink  
Comments
Espen Harlinn - 20 Sep '12 - 4:16
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
Your Filters
Interested
Ignored
     
0 Mohammed Hameed 268
1 OriginalGriff 261
2 Sergey Alexandrovich Kryukov 188
3 Mayur_Panchal 153
4 Santhosh G_ 108
0 Sergey Alexandrovich Kryukov 8,216
1 OriginalGriff 6,271
2 CPallini 3,528
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 19 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid