Referencing textbox

  • Thread starter Thread starter Morten Snedker
  • Start date Start date
M

Morten Snedker

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
 
Hi,

Morten said:
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
 
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
 
On Tue, 23 Jan 2007 08:59:00 -0500, "Karl Seguin [MVP]"

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
 
TextBox txt = Page.FindControl(string.Format("txt{0}_effket", _someId)) as
TextBox;
if (txt == null)
{
//something bad happened
}


Karl
 
Hi,
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
 
On Tue, 23 Jan 2007 10:12:05 -0500, "Karl Seguin [MVP]"

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

Regards /Snedker
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top