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

textbox text property empty when added at runtime

9
This should be fairly trivial I think..but is not working.
I have a textbox that i add at runtime

TextBox tagText = new TextBox();

then i put it in a panel'

PanelWODetails.Controls.Add(tagText);

once the user enters some text and click on a button I try to grab that text, but the Text property is always empty.

any ideas why this would happen?
Apr 8 '09 #1
5 4446
tlhintoq
3,525 Expert 2GB
let's see the code where you are trying to get the text; maybe the issue is there
Apr 8 '09 #2
cyrak
9
ok..so what i do to get it is
I save all the textboxes in a collection so that I don't have to find them in the controls collection ( I assume this shouldn't be a problem given C# only uses references...maybe this is bad assumption(?) ) and then i just do
Expand|Select|Wrap|Line Numbers
  1. //words is a regular string array
  2. words[i] = ((TextBox)TBoxes[boxNumber]).Text;
edit:
///ok so this is kind of weird to me... right after I finish creating the textboxes i make a copy of the panel's control collection and put it in a Session variable.
When Postback happens the panel's controls are gone but the session variable still has all of them and the last line executing is

Expand|Select|Wrap|Line Numbers
  1. Session["collection"] = PanelWODetails.Controls;
and when postback happens the PanelWO.Details controls are gone..there is just a literal there
Apr 8 '09 #3
Frinavale
9,735 Expert Mod 8TB
You have to instantiate your TextBox in the Page Init Event.
Please see the article about how to use dynamic controls in ASP.NET for more information on why. (Sorry that the code is in VB.NET but the concepts in that article are important to grasp)

-Frinny
Apr 9 '09 #4
cyrak
9
thank you! that explains the why..
Now your article only adds up to 6 textboxes
my webapp parses text from a selectedCell in a gridview and when it finds a certain word it adds a textbox to a panel...there could be 2 or 70 I don't find it very wise to instantiate a whole bunch of textboxes when i might be only using 2 and i also need to have some labels in between those textboxes...is it really the only way?
Apr 12 '09 #5
Frinavale
9,735 Expert Mod 8TB
Hmmm, you don't have to use an Array to store the TextBoxes and Lables, that was just for simplicity sake for the article.

You could try storing them in a generic List(T) so that the list can grow to the size you require...

You'll need to store the number of TextBoxes and Labels somewhere so that you know how many to instantiate during the Page Init event.

I would recommend storing them in a cookie, HiddenField, or as parameters in the URL so that you can grab these values from the Request Object. Remember that you can't store this value in ViewState because it's not available at this stage in the page's life cycle.
Apr 13 '09 #6

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

Similar topics

1
by: Alexander | last post by:
I am building a little unique dialog editor and have derived some new classes like DButton, DLabel and DTextBox. The user adds these Controls to a panel which is part of a class Document which is...
1
by: Johann Blake | last post by:
I have a form with a single textbox control which is bound to a DataRelation in a typed dataset. The textbox displays the name of the product depending on the language selected from a combobox....
5
by: JollyK | last post by:
Hello all, I have always been having this issue and wondering what the solution is. When I set the enableviewstate property to false for a textbox, the textbox always retains its value after a...
11
by: Joe | last post by:
Hello All, I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton (SearchButton) server controls. The user can type search text in SearchTextBox and click SearchButton and...
3
by: Barry | last post by:
A beginners question to someone that isn't a beginner ;) I've forgotton a lot. The code below isn't what I want to do but it demonstrates succinctly my problem. I want to drop a "MyTextBox"...
1
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
1
by: shapper | last post by:
Hello, I am working on Library which will include various controls. One of these controls has a TextBox. I am using a property named Value to define the TextBox text: ' Value Private...
6
by: =?Utf-8?B?SFJzb2Z0IEluZm9ybcOhdGljYQ==?= | last post by:
I Have a page (clientes.aspx), inside a masterpage I have some textbox, and when the user clicks the button 'Cancel', I need to empty all controls. I tried this, with runtine error: For Each...
3
by: Avi | last post by:
Hi all, I have a web page with Multiline TextBox. Every 3 seconds I refresh the page and display all received messages in this TextBox. When the TextBox is updated (The Text property is set). ...
1
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.