473,805 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrive value of dynamic control

satiss7pwr
41 New Member
i am creating dynamic text box and dropdownlist on one DropDownList7_S electedIndexCha nged 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 1611
Frinavale
9,735 Recognized Expert Moderator Expert
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
2013
by: Balamurukan | last post by:
How to retrive property values from our own property window
1
2705
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 depending on the return value from the process just completed on the second thread. The problem I am having is that while the code seems to work correctly (I am performing a response.write and writting out the values as a HTML comment), the final...
3
1412
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 awkward or I don't know how to pose the question correctly. Let me try again. I appreciate any input! :-) I have an asp.net web form with a TextBox control and a submit button. The TextBox control's text property is set on the server before it...
2
2939
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 the Page Load event works, and I realize that I need to add the dynamic controls again on each postback. But if I'm trying to retrieve the value of a dynamic control (Text property of a TextBox for instance), should I retrieve the value in the...
2
7702
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 Content/MasterPage setup, the MasterPage Form seems to be interfering with the ability of my code to retrieve the value in the dynamic control. Are there any ideas on why this is happening or how to work-around the problem? What is the syntax to find a...
0
1277
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 value 8080 from the file and assign it to portno,so that when i am using portno in my program it will be replaced by 8080.
1
1185
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 need to retrieve the value of it, before it's created... how do I do this?
0
1158
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 filterbutton_Click event and i call createcontrols function(public) in that ).But when i select value of that control(dynamic created) in another button click event(searchbutton) first it create fuction does not create dynamic control second as a result i...
1
1679
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" value="<%=name%>"> [/code>
12
24820
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 click the button, it will populate a dynamic table with radio button for the survey questionnaire However, i was unable to get its value (for score calculation) after clicking the submit button Beside i am using an ajax extension (updatePanel) for the...
0
9596
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10369
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6876
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
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
2
3847
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.