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

Referencing textbox

Im trying to set value of a textbox, but it fails.

txtBox.Text = obj.Effekt does nothing on the page, but the last one
does.

Fieldname is positively correct.

What am I doing wrong?

Dim listNr As String = Right(ListName, 1)
Dim FieldName As String = "txt5" & listNr & "_effekt"

Dim txtBox As New TextBox
txtBox.ID = FieldName

Dim obj As Naturgas
obj = CType(_naturgasList(idx), Naturgas)

txtBox.Text = obj.Effekt
Me.txt51_effekt.Text = obj.Effekt
/Snedker
Jan 23 '07 #1
6 1019
Hi,

Morten Snedker wrote:
Im trying to set value of a textbox, but it fails.

txtBox.Text = obj.Effekt does nothing on the page, but the last one
does.

Fieldname is positively correct.

What am I doing wrong?

Dim listNr As String = Right(ListName, 1)
Dim FieldName As String = "txt5" & listNr & "_effekt"

Dim txtBox As New TextBox
txtBox.ID = FieldName

Dim obj As Naturgas
obj = CType(_naturgasList(idx), Naturgas)

txtBox.Text = obj.Effekt
Me.txt51_effekt.Text = obj.Effekt
/Snedker
You create a brand new TextBox, but you don't add it to the Page. It's
just an object which will be deleted as soon as the Page is recycled
(when the Response is sent).

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 23 '07 #2
You are never adding the txtBox to the page...you need a placeholder or some
other container on the page..
myPlaceholder.Controls.Add(txtBox);

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Morten Snedker" <morten_spammenot_ATdbconsult.dkwrote in message
news:c0********************************@4ax.com...
Im trying to set value of a textbox, but it fails.

txtBox.Text = obj.Effekt does nothing on the page, but the last one
does.

Fieldname is positively correct.

What am I doing wrong?

Dim listNr As String = Right(ListName, 1)
Dim FieldName As String = "txt5" & listNr & "_effekt"

Dim txtBox As New TextBox
txtBox.ID = FieldName

Dim obj As Naturgas
obj = CType(_naturgasList(idx), Naturgas)

txtBox.Text = obj.Effekt
Me.txt51_effekt.Text = obj.Effekt
/Snedker
Jan 23 '07 #3
On Tue, 23 Jan 2007 08:59:00 -0500, "Karl Seguin [MVP]"
<ka********@removeopenmymindremovemetoo.andmenetwr ote:

Thanks to the both of you. It seems I haven't explained myself
properly:

I have txt51_effekt, txt52_effekt..txt55_effekt

What I'm trying to do is to reference these dynamically, not creating
new ones. So I guess I got it all wrong. :-\

So, how do I reference each of them dynamically?

Regards /Snedker
Jan 23 '07 #4
TextBox txt = Page.FindControl(string.Format("txt{0}_effket", _someId)) as
TextBox;
if (txt == null)
{
//something bad happened
}
Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Morten Snedker" <morten_spammenot_ATdbconsult.dkwrote in message
news:54********************************@4ax.com...
On Tue, 23 Jan 2007 08:59:00 -0500, "Karl Seguin [MVP]"
<ka********@removeopenmymindremovemetoo.andmenetwr ote:

Thanks to the both of you. It seems I haven't explained myself
properly:

I have txt51_effekt, txt52_effekt..txt55_effekt

What I'm trying to do is to reference these dynamically, not creating
new ones. So I guess I got it all wrong. :-\

So, how do I reference each of them dynamically?

Regards /Snedker
Jan 23 '07 #5
Hi,

Karl Seguin [MVP] wrote:
TextBox txt = Page.FindControl(string.Format("txt{0}_effket", _someId))
as TextBox;
if (txt == null)
{
//something bad happened
}
Karl
Careful to translate that to VB.NET before compiling, though ;-)

Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 23 '07 #6
On Tue, 23 Jan 2007 10:12:05 -0500, "Karl Seguin [MVP]"
<ka********@removeopenmymindremovemetoo.andmenetwr ote:

Worked like a charm! Thanks a bunch to each of you for your help!

Regards /Snedker
Jan 24 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: 2obvious | last post by:
I have a DataGrid containing a TextBox control and a CustomValidator in each row. The CustomValidator fires a function that compares all TextBoxes for equality. The algorithm for comparison...
3
by: 2obvious | last post by:
I have a DataGrid containing a TextBox control and a CustomValidator in each row. The CustomValidator fires a function that compares all TextBoxes for equality. The algorithm for comparison is...
3
by: markh | last post by:
Does anyone know where i could find a good website that explains many techniques for direct control referencing? thanks markh
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
0
by: sansie | last post by:
Hi, I have a page which is basically a details view(in inset mode) inside a datalist. The problem is I want to set the field "invoiceID" (of the detailsview) to an invoiceID coming through the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.