473,320 Members | 1,933 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,320 software developers and data experts.

Retrive value of dynamic control

satiss7pwr
i am creating dynamic text box and dropdownlist on one DropDownList7_SelectedIndexChanged event like this code
Expand|Select|Wrap|Line Numbers
  1. public partial class AddMethod : System.Web.UI.Page
  2. {
  3.  
  4.     DropDownList drp=null ;
  5.     TextBox txt=null  ;
  6.     int z;// it store store DropDownList7.SelectedValue
  7. .
  8. .
  9. .
  10.  
  11. protected void DropDownList7_SelectedIndexChanged(object sender, EventArgs e)//this dropdown having static mebers like 1,2,3,...so on and as its value i want to create no of textbox and dropdowns
  12.     {
  13.  
  14.         z = int.Parse(DropDownList7.SelectedValue);
  15.         while(z > 0)
  16.             { 
  17.                 drp = new DropDownList();
  18.                 txt = new TextBox();
  19.                 drp.ID=Convert.ToString(z); 
  20.                 txt.ID="txt"+Convert.ToString(z);
  21.  
  22.                 drp.Items.Add(new ListItem("int"));
  23.                 drp.Items.Add(new ListItem("float"));
  24.                 drp.Items.Add(new ListItem("string"));
  25.                 drp.Items.Add(new ListItem("boolean"));
  26.  
  27.  
  28.                 Panel1.Controls.Add(drp);
  29.  
  30.                 Panel1.Controls.Add(txt);
  31.  
  32.  
  33.                 z--;
  34.             }
  35.  }
And how i can get values of this dynamic controls.
i have try this code but it not worked,i try to get this values on button clik event like this
Expand|Select|Wrap|Line Numbers
  1. protected void Button6_Click(object sender, EventArgs e)
  2.     {
  3.  
  4.         for (int t = 1; t <= z; t++)
  5.         {
  6.             string tn = "txt" + t;
  7.            // TextBox txt = (TextBox)Panel1.FindControl("txt" +t);
  8.             //TextBox txt = Panel1.FindControl(tn) as TextBox;
  9.             TextBox txt = PlaceHolder1.FindControl(tn) as TextBox;
  10.              string tname=txt.Text;
  11.  
  12.         }
  13. }

plese any one help me
i f im going wrong to writing code than pls suggest me
im reaching final step to my project plsssss
Apr 21 '10 #1
1 1594
Frinavale
9,735 Expert Mod 8TB
You are doing something wrong.
You cannot create dynamic ASP.NET controls in a method that handles an Event. You have to create them before this point (in the Page Init event) or else you will not be able to retrieve the values in subsequent postbacks to the server.

Please review this article on how to use dynamic controls in ASP.NET.

-Frinny

PS.

Please post code in code tags. It makes code easier for us to read and it provides us with line numbers that we can refer to when helping you.
Apr 21 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Balamurukan | last post by:
How to retrive property values from our own property window
1
by: amirmira | last post by:
I have a multithreaded application is ASP.NET that checks the status of a process every 2 seconds. After the thread has completed, the values of dynamically added controls need to be changed...
3
by: epigram | last post by:
I've tried asking this question several times and have received many good answers, but ones that don't quite answer my question. This leads me to believe that I am trying to do something very...
2
by: Ben Amada | last post by:
I'm a little confused about in what Event should I add dynamic controls and in what Event should I retrieve the value of a dynamic control on postback. I've found that adding dynamic controls in...
2
by: dawg1998 | last post by:
I have a page that creates dynamic textboxes based on the number of fields a user chooses to fill out. This process worked great when the page was standalone. However, when I move to a...
0
by: avishekb | last post by:
can anyone suggest me how to retrive data from a xml file using c/c++. for example: <schema> <applt to>portno</applyto> <type>int</type> <value>8080</value> </schema> i want to retrive the...
1
by: Larry Bud | last post by:
A dynamic control (A dropdown) is created in PageLoad, but the value of the dynamic control dictates where it's added (such as which cell in a table) on a postback. Seems like a catch-22. I...
0
by: imranabdulaziz | last post by:
hi all , i am mess with the one situation. i am using asp.net2.0 ,C# and sql server 2005. I have checkboxlist and based on user selection i creates dynamic controls(which code is in...
1
idsanjeev
by: idsanjeev | last post by:
hello i wants to retrive data in textarea like input text but in textarea value is not work so what should be use to retrive textarea value after any error <input type="text" name="name"...
12
by: ive1122 | last post by:
Hi guys, I am looking into create a dynamic survey as posted in Get User Input From Dynamic Controls but with some different environment Below is what i am trying to do: First when the user...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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)...
0
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: 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...

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.