473,468 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with dynamically adding controls to panel

2 New Member
hai........
i have an asp.net page.with four text box controls.I also have a link button .
i want to add 4 text boxes each time i click on the link button.I write code for this but it didnt works well.Only the first time it creates 4 text boxes but when i click the link button again the text box controls are not displayed.

here is my code
Expand|Select|Wrap|Line Numbers
  1. static count=0;
  2. protected void LinkButton1_Click(object sender, EventArgs e)
  3.     {
  4.             int q;
  5.  
  6.                q = count + 1;
  7.                 TextBox t1 = new TextBox();
  8.                 t1.ID = "a" + q.ToString();
  9.                 TextBox t2 = new TextBox();
  10.                 t2.ID = "b" + q;
  11.                 TextBox t3 = new TextBox();
  12.                 t3.ID = "c" + q;
  13.                 TextBox t4 = new TextBox();
  14.                 t4.ID = "d" + q;
  15.                 Panel1.Controls.Add(t1);
  16.                 Panel2.Controls.Add(t2);
  17.                 Panel3.Controls.Add(t3);
  18.                 Panel4.Controls.Add(t4);
  19.                Panel1.Visible = true;
  20.                Panel2.Visible = true;
  21.                Panel3.Visible = true;
  22.                Panel4.Visible = true;
  23.               count = count + 1;
  24.               Response.Write(Panel1.Controls.Count);
  25.  
  26.         }
  27.  
Plese give me a solution
Jul 25 '08 #1
3 979
Curtis Rutland
3,256 Recognized Expert Specialist
I'm not sure if that static value persists between postbacks. Try putting your count value in a hidden field.
Jul 25 '08 #2
tlhintoq
3,525 Recognized Expert Specialist
Maybe, maybe not....

I had a similar problem with creating controls on a form. I swore they weren't being created. Then I realized they really were being created, but without specifying their location they were all being created on top of each other, thus looking like one.

If you are only going by what it *looks* like is happening remember: Looks can be deceiving. Perhaps while debugging have the creation loop exit into a message box telling you how many total controls were made.

Then again, might be something entirely different.
Jul 26 '08 #3
Frinavale
9,735 Recognized Expert Moderator Expert
hai........

Plese give me a solution
We are here to help you find the solution to your problem, but will not outright give you the answer to your problem.

Please check out the article on How to use dynamic controls in ASP.NET...it maybe of some use to you.

-Moderator Frinny
Jul 28 '08 #4

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

Similar topics

9
by: Matt Tapia | last post by:
I having a problem that receives the following error: Specified cast is not valid And I need some help. Here is what is happening: I have a form with a drop-down control that contains a list...
4
by: epigram | last post by:
I've got a page that has a Panel object that I am dynamically adding CheckBox controls to. The number of CheckBox controls and the name of each control is based on a database query. I would like...
7
by: Dino Buljubasic | last post by:
Hi, I am using C# 2.0 (VS2005) to build my user control that contains a number of dynamically loaded ListViews. ListViewItems have their ForeColor properties set to either black or blue to...
1
by: Carol | last post by:
Hi, I am working in C# I have created one usercontrol. Now added a panel to this control. In a panel i have added another control. Now, i have added this usercontrol to a form. Now, on button...
2
by: Jarod | last post by:
Hey I change backColor of linkButton in my Page_Load: lbDoSth.BackColor = Color.Red; But I have multiView on this page. On one of the views I have detailsView. When I add a new row a set...
4
by: Chris | last post by:
I have some code which adds controls to a placeholder. The button and label however always appears above the dynamically added content when the actual tags are below. Why is this. I want them to...
3
by: s9213037 | last post by:
Use case scenario: I have a panel with ID "Upload_Panel", where there is a FileUpload control with ID "FileUpload1" and a button with ID "More_Upload_Files", both of which are added at design...
0
by: Gibble | last post by:
Hi, I can't seem to get my control to render properly. When I just placed it on the page it was working fine...and the RenderContents sub is getting fired...I'm guessing it's just too late??? ...
0
by: Syoam4ka | last post by:
My project is about jewellery. I have devided my jewelery into main types, which each one of them has sub types, and each one those sub types has the jewellery. I have a tabcontainer. It includes...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.