By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,137 Members | 2,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,137 IT Pros & Developers. It's quick & easy.

Why can't I set the textbox "text" property??

P: n/a
Can anyone help? I have a textbox which I'm programatically adding by
using the following code:
txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
Page.FindControl("tdInput").Controls.Add(txtTest)
This successfully creates a textbox called "txtLeft1" in the table
cell "tdInput". Now the next thing I'm doing is this:
Dim txtLeft1 As TextBox
txtLeft1 = Page.FindControl("txtLeft1")
txtLeft1.Text = "Computer"
txtLeft1.BackColor = Color.AliceBlue
....which I'm wanting to change the value of the text in the textbox to
"Computer". However, for some reason it doesn't seem to be working. I
know it's almost certainly something really, really obvious but I just
can't see what it is. I included the last line to change the back
colour, just to check that the textbox control is being found by the
script, and it is indeed. The problem is that it just will not set the
text.
Things I've tried so far that either don't work or are spat out by
Visual Studio are:

txtLeft1.Value = "Computer"

txtLeft1.Text.Value = "Computer"

txtLeft1.Text = "Computer".ToString

txtLeft1.Text = "Computer".ToCharArray

txtLeft1.Text = "Computer"
txtLeft1.DataBind()
If anyone can spot the glaringly obvious here, I'd be immensely
grateful!

Apr 30 '07 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Your code works for me.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim txtTest As TextBox
Dim cntCount As Integer = 1
txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
Page.FindControl("tdInput").Controls.Add(txtTest)
Dim txtLeft1 As TextBox
txtLeft1 = Page.FindControl("txtLeft1")
txtLeft1.Text = "Computer"
txtLeft1.BackColor = Drawing.Color.AliceBlue
End Sub
May I suggest that instead of creating a textbox, adding it, and then
creating a new instance of a textbox that is the same one, you just set the
text and color when you create the initial textbox?
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim txtTest As TextBox
Dim cntCount As Integer = 1
txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
txtTest.BackColor = Drawing.Color.AliceBlue
txtTest.Text = "Computer"
Page.FindControl("tdInput").Controls.Add(txtTest)
End Sub

Ray at work

<mj**********@gmail.comwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
Can anyone help? I have a textbox which I'm programatically adding by
using the following code:
txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
Page.FindControl("tdInput").Controls.Add(txtTest)
This successfully creates a textbox called "txtLeft1" in the table
cell "tdInput". Now the next thing I'm doing is this:
Dim txtLeft1 As TextBox
txtLeft1 = Page.FindControl("txtLeft1")
txtLeft1.Text = "Computer"
txtLeft1.BackColor = Color.AliceBlue
...which I'm wanting to change the value of the text in the textbox to
"Computer". However, for some reason it doesn't seem to be working. I
know it's almost certainly something really, really obvious but I just
can't see what it is. I included the last line to change the back
colour, just to check that the textbox control is being found by the
script, and it is indeed. The problem is that it just will not set the
text.
Things I've tried so far that either don't work or are spat out by
Visual Studio are:

txtLeft1.Value = "Computer"

txtLeft1.Text.Value = "Computer"

txtLeft1.Text = "Computer".ToString

txtLeft1.Text = "Computer".ToCharArray
Apr 30 '07 #2

P: n/a
Thanks Ray, at least you've shown I wasn't too far off the right track
I guess!

I'll give that a shot.
On 30 Apr, 15:47, "Ray Costanzo" <my first name at lane 34 dot
commercialwrote:
Your code works for me.

*Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
* Dim txtTest As TextBox
* Dim cntCount As Integer = 1
* txtTest = New TextBox
* txtTest.ID = "txtLeft" + cntCount.ToString
* Page.FindControl("tdInput").Controls.Add(txtTest)
* Dim txtLeft1 As TextBox
* txtLeft1 = Page.FindControl("txtLeft1")
* txtLeft1.Text = "Computer"
* txtLeft1.BackColor = Drawing.Color.AliceBlue
*End Sub

May I suggest that instead of creating a textbox, adding it, and then
creating a new instance of a textbox that is the same one, you just set the
text and color when you create the initial textbox?

*Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
* Dim txtTest As TextBox
* Dim cntCount As Integer = 1
* txtTest = New TextBox
* txtTest.ID = "txtLeft" + cntCount.ToString
* txtTest.BackColor = Drawing.Color.AliceBlue
* txtTest.Text = "Computer"
* Page.FindControl("tdInput").Controls.Add(txtTest)
*End Sub

Ray at work

<mj.redfox...@gmail.comwrote in message

news:11**********************@y80g2000hsf.googlegr oups.com...
Can anyone help? I have a textbox which I'm programatically adding by
using the following code:
txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
Page.FindControl("tdInput").Controls.Add(txtTest)
This successfully creates a textbox called "txtLeft1" in the table
cell "tdInput". Now the next thing I'm doing is this:
Dim txtLeft1 As TextBox
txtLeft1 = Page.FindControl("txtLeft1")
txtLeft1.Text = "Computer"
txtLeft1.BackColor = Color.AliceBlue
...which I'm wanting to change the value of the text in the textbox to
"Computer". However, for some reason it doesn't seem to be working. I
know it's almost certainly something really, really obvious but I just
can't see what it is. I included the last line to change the back
colour, just to check that the textbox control is being found by the
script, and it is indeed. The problem is that it just will not set the
text.
Things I've tried so far that either don't work or are spat out by
Visual Studio are:
txtLeft1.Value = "Computer"
txtLeft1.Text.Value = "Computer"
txtLeft1.Text = "Computer".ToString
txtLeft1.Text = "Computer".ToCharArray- Hide quoted text -

- Show quoted text -

Apr 30 '07 #3

P: n/a
Not at all. :]

Ray at work

<mj**********@gmail.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
Thanks Ray, at least you've shown I wasn't too far off the right track
I guess!

I'll give that a shot.
On 30 Apr, 15:47, "Ray Costanzo" <my first name at lane 34 dot
commercialwrote:
Your code works for me.\
Apr 30 '07 #4

P: n/a
Hmmmm. The textboxes (there are a few of them created by a FOR...NEXT
loop) are actually behaving VERY weirdly, using your suggestion I can
now assign a text value to all but the first two, even though the loop
handles them all identically!!????

I'll have another look tomorrow and then report back as this may be
useful for other people in the future. I wonder if dynamic generated
form elements are just unstable in general?
On 30 Apr, 16:14, "Ray Costanzo" <my first name at lane 34 dot
commercialwrote:
Not at all. :]

Ray at work

<mj.redfox...@gmail.comwrote in message

news:11**********************@e65g2000hsc.googlegr oups.com...
Thanks Ray, at least you've shown I wasn't too far off the right track
I guess!

I'll give that a shot.

On 30 Apr, 15:47, "Ray Costanzo" <my first name at lane 34 dot

commercialwrote:
Your code works for me.\- Hide quoted text -

- Show quoted text -

Apr 30 '07 #5

P: n/a
It's possible that what you're trying to do can be done with an entirely
different approach. If you want to post snippets of ASPX and .VB that would
be enough for us to duplicate what you're doing, maybe someone could offer
some alternate routes if they'd seem appropriate.

Ray at work

<mj**********@gmail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
Hmmmm. The textboxes (there are a few of them created by a FOR...NEXT
loop) are actually behaving VERY weirdly, using your suggestion I can
now assign a text value to all but the first two, even though the loop
handles them all identically!!????

I'll have another look tomorrow and then report back as this may be
useful for other people in the future. I wonder if dynamic generated
form elements are just unstable in general?
Apr 30 '07 #6

P: n/a
OK, here's the code behind page in full. I didn't post this originally
as it's in a very 'quick and dirty' state at the moment, and needs
tidied, commented and the variables renamed...but this is what I've
been working with It basically adds a variable number of table cells
and textboxes within them, based on the value of 'intAttributes'.
Using this, for some reason I can only set properties of textboxes
txtLeft2 - txtLeft8 (or whatever the upper limit is) - any attempt to
programmatically change the initial text in textboxes txtTest0 or
txtTest1 has no effect. Very, very strange.
Partial Class _ShowData
Inherits System.Web.UI.Page

Sub Page_Load(ByVal Sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim strTemplate As String
Dim intAttributes As Integer
Dim txtTest As TextBox
Dim trTest As TableRow
Dim tdTest As TableCell
Dim cntCount As Integer

strTemplate = ""
intAttributes = 1

If Page.IsPostBack Then
If Page.Request.Params.Get("__EVENTTARGET") =
"DropDownList1" Then
strTemplate = DropDownList1.Text
Select Case DropDownList1.Text
Case "Computer"
intAttributes = 8
Case "Generic"
intAttributes = 6
End Select
End If
End If

For cntCount = 1 To intAttributes

trTest = New TableRow
trTest.ID = "trSpecification" + cntCount.ToString
Page.FindControl("tblSpecification").Controls.Add( trTest)

tdTest = New TableCell
tdTest.ID = "tdSpecificationLeft" + cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)

tdTest = New TableCell
tdTest.ID = "tdSpecificationRight" + cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)

txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
If strTemplate = "Computer" Then
If cntCount = 0 Then
txtTest.Text = "Test Text 0"
End If
If cntCount = 1 Then
txtTest.Text = "Test Text 1"
End If
If cntCount = 2 Then
txtTest.Text = "Test Text 2"
End If
End If
Page.FindControl("tdSpecificationLeft" +
cntCount.ToString).Controls.Add(txtTest)

txtTest = New TextBox
txtTest.ID = "txtRight" + cntCount.ToString
Page.FindControl("tdSpecificationRight" +
cntCount.ToString).Controls.Add(txtTest)

Next

End Sub

On 30 Apr, 16:55, "Ray Costanzo" <my first name at lane 34 dot
commercialwrote:
It's possible that what you're trying to do can be done with an entirely
different approach. If you want to post snippets of ASPX and .VB that would
be enough for us to duplicate what you're doing, maybe someone could offer
some alternate routes if they'd seem appropriate.

Ray at work

<mj.redfox...@gmail.comwrote in message

news:11*********************@p77g2000hsh.googlegro ups.com...
Hmmmm. The textboxes (there are a few of them created by a FOR...NEXT
loop) are actually behaving VERY weirdly, using your suggestion I can
now assign a text value to all but the first two, even though the loop
handles them all identically!!????
I'll have another look tomorrow and then report back as this may be
useful for other people in the future. I wonder if dynamic generated
form elements are just unstable in general?- Hide quoted text -

- Show quoted text -

May 1 '07 #7

P: n/a
QUICK ADD: For some reason, in the above I've accidentally deleted the
line where if 'Computer' is selected in the drop-down list, then
strTemplate is set to "Computer". Sorry about that, the important
point in the above is that the line that adds the text to textbox
txtLeft2 works fine, so I just need to figure out what is so 'special'
about textboxes 1 and 2...
On 1 May, 08:31, mj.redfox...@gmail.com wrote:
OK, here's the code behind page in full. I didn't post this originally
as it's in a very 'quick and dirty' state at the moment, and needs
tidied, commented and the variables renamed...but this is what I've
been working with It basically adds a variable number of table cells
and textboxes within them, based on the value of 'intAttributes'.
Using this, for some reason I can only set properties of textboxes
txtLeft2 - txtLeft8 (or whatever the upper limit is) - any attempt to
programmatically change the initial text in textboxes txtTest0 or
txtTest1 has no effect. Very, very strange.

Partial Class _ShowData
Inherits System.Web.UI.Page

Sub Page_Load(ByVal Sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim strTemplate As String
Dim intAttributes As Integer
Dim txtTest As TextBox
Dim trTest As TableRow
Dim tdTest As TableCell
Dim cntCount As Integer

strTemplate = ""
intAttributes = 1

If Page.IsPostBack Then
If Page.Request.Params.Get("__EVENTTARGET") =
"DropDownList1" Then
strTemplate = DropDownList1.Text
Select Case DropDownList1.Text
Case "Computer"
intAttributes = 8
Case "Generic"
intAttributes = 6
End Select
End If
End If

For cntCount = 1 To intAttributes

trTest = New TableRow
trTest.ID = "trSpecification" + cntCount.ToString
Page.FindControl("tblSpecification").Controls.Add( trTest)

tdTest = New TableCell
tdTest.ID = "tdSpecificationLeft" + cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)

tdTest = New TableCell
tdTest.ID = "tdSpecificationRight" + cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)

txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
If strTemplate = "Computer" Then
If cntCount = 0 Then
txtTest.Text = "Test Text 0"
End If
If cntCount = 1 Then
txtTest.Text = "Test Text 1"
End If
If cntCount = 2 Then
txtTest.Text = "Test Text 2"
End If
End If
Page.FindControl("tdSpecificationLeft" +
cntCount.ToString).Controls.Add(txtTest)

txtTest = New TextBox
txtTest.ID = "txtRight" + cntCount.ToString
Page.FindControl("tdSpecificationRight" +
cntCount.ToString).Controls.Add(txtTest)

Next

End Sub

On 30 Apr, 16:55, "Ray Costanzo" <my first name at lane 34 dot

commercialwrote:
It's possible that what you're trying to do can be done with an entirely
different approach. If you want to post snippets of ASPX and .VB that would
be enough for us to duplicate what you're doing, maybe someone could offer
some alternate routes if they'd seem appropriate.
Ray at work
<mj.redfox...@gmail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
Hmmmm. The textboxes (there are a few of them created by a FOR...NEXT
loop) are actually behaving VERY weirdly, using your suggestion I can
now assign a text value to all but the first two, even though the loop
handles them all identically!!????
I'll have another look tomorrow and then report back as this may be
useful for other people in the future. I wonder if dynamic generated
form elements are just unstable in general?- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

May 1 '07 #8

P: n/a
cntCount will never be 0 as you start it from 1.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
<mj**********@gmail.comwrote in message
news:11**********************@c35g2000hsg.googlegr oups.com...
QUICK ADD: For some reason, in the above I've accidentally deleted the
line where if 'Computer' is selected in the drop-down list, then
strTemplate is set to "Computer". Sorry about that, the important
point in the above is that the line that adds the text to textbox
txtLeft2 works fine, so I just need to figure out what is so 'special'
about textboxes 1 and 2...
On 1 May, 08:31, mj.redfox...@gmail.com wrote:
>OK, here's the code behind page in full. I didn't post this originally
as it's in a very 'quick and dirty' state at the moment, and needs
tidied, commented and the variables renamed...but this is what I've
been working with It basically adds a variable number of table cells
and textboxes within them, based on the value of 'intAttributes'.
Using this, for some reason I can only set properties of textboxes
txtLeft2 - txtLeft8 (or whatever the upper limit is) - any attempt to
programmatically change the initial text in textboxes txtTest0 or
txtTest1 has no effect. Very, very strange.

Partial Class _ShowData
Inherits System.Web.UI.Page

Sub Page_Load(ByVal Sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim strTemplate As String
Dim intAttributes As Integer
Dim txtTest As TextBox
Dim trTest As TableRow
Dim tdTest As TableCell
Dim cntCount As Integer

strTemplate = ""
intAttributes = 1

If Page.IsPostBack Then
If Page.Request.Params.Get("__EVENTTARGET") =
"DropDownList1" Then
strTemplate = DropDownList1.Text
Select Case DropDownList1.Text
Case "Computer"
intAttributes = 8
Case "Generic"
intAttributes = 6
End Select
End If
End If

For cntCount = 1 To intAttributes

trTest = New TableRow
trTest.ID = "trSpecification" + cntCount.ToString
Page.FindControl("tblSpecification").Controls.Add( trTest)

tdTest = New TableCell
tdTest.ID = "tdSpecificationLeft" + cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)

tdTest = New TableCell
tdTest.ID = "tdSpecificationRight" + cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)

txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
If strTemplate = "Computer" Then
If cntCount = 0 Then
txtTest.Text = "Test Text 0"
End If
If cntCount = 1 Then
txtTest.Text = "Test Text 1"
End If
If cntCount = 2 Then
txtTest.Text = "Test Text 2"
End If
End If
Page.FindControl("tdSpecificationLeft" +
cntCount.ToString).Controls.Add(txtTest)

txtTest = New TextBox
txtTest.ID = "txtRight" + cntCount.ToString
Page.FindControl("tdSpecificationRight" +
cntCount.ToString).Controls.Add(txtTest)

Next

End Sub

On 30 Apr, 16:55, "Ray Costanzo" <my first name at lane 34 dot

commercialwrote:
It's possible that what you're trying to do can be done with an
entirely
different approach. If you want to post snippets of ASPX and .VB that
would
be enough for us to duplicate what you're doing, maybe someone could
offer
some alternate routes if they'd seem appropriate.
Ray at work
<mj.redfox...@gmail.comwrote in message
>news:11*********************@p77g2000hsh.googlegr oups.com...
Hmmmm. The textboxes (there are a few of them created by a FOR...NEXT
loop) are actually behaving VERY weirdly, using your suggestion I can
now assign a text value to all but the first two, even though the
loop
handles them all identically!!????
I'll have another look tomorrow and then report back as this may be
useful for other people in the future. I wonder if dynamic generated
form elements are just unstable in general?- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -


May 1 '07 #9

P: n/a
I've tried it from 0 though for testing purposes, again couldn't set
the text for that textbox but could for all the ones from 2 onwards.
On 1 May, 09:19, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
cntCount will never be 0 as you start it from 1.

--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com- Local franchises available

<mj.redfox...@gmail.comwrote in message

news:11**********************@c35g2000hsg.googlegr oups.com...
QUICK ADD: For some reason, in the above I've accidentally deleted the
line where if 'Computer' is selected in the drop-down list, then
strTemplate is set to "Computer". Sorry about that, the important
point in the above is that the line that adds the text to textbox
txtLeft2 works fine, so I just need to figure out what is so 'special'
about textboxes 1 and 2...
On 1 May, 08:31, mj.redfox...@gmail.com wrote:
OK, here's the code behind page in full. I didn't post this originally
as it's in a very 'quick and dirty' state at the moment, and needs
tidied, commented and the variables renamed...but this is what I've
been working with It basically adds a variable number of table cells
and textboxes within them, based on the value of 'intAttributes'.
Using this, for some reason I can only set properties of textboxes
txtLeft2 - txtLeft8 (or whatever the upper limit is) - any attempt to
programmatically change the initial text in textboxes txtTest0 or
txtTest1 has no effect. Very, very strange.
Partial Class _ShowData
Inherits System.Web.UI.Page
Sub Page_Load(ByVal Sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strTemplate As String
Dim intAttributes As Integer
Dim txtTest As TextBox
Dim trTest As TableRow
Dim tdTest As TableCell
Dim cntCount As Integer
strTemplate = ""
intAttributes = 1
If Page.IsPostBack Then
If Page.Request.Params.Get("__EVENTTARGET") =
"DropDownList1" Then
strTemplate = DropDownList1.Text
Select Case DropDownList1.Text
Case "Computer"
intAttributes = 8
Case "Generic"
intAttributes = 6
End Select
End If
End If
For cntCount = 1 To intAttributes
trTest = New TableRow
trTest.ID = "trSpecification" + cntCount.ToString
Page.FindControl("tblSpecification").Controls.Add( trTest)
tdTest = New TableCell
tdTest.ID = "tdSpecificationLeft" + cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)
tdTest = New TableCell
tdTest.ID = "tdSpecificationRight" + cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)
txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
If strTemplate = "Computer" Then
If cntCount = 0 Then
txtTest.Text = "Test Text 0"
End If
If cntCount = 1 Then
txtTest.Text = "Test Text 1"
End If
If cntCount = 2 Then
txtTest.Text = "Test Text 2"
End If
End If
Page.FindControl("tdSpecificationLeft" +
cntCount.ToString).Controls.Add(txtTest)
txtTest = New TextBox
txtTest.ID = "txtRight" + cntCount.ToString
Page.FindControl("tdSpecificationRight" +
cntCount.ToString).Controls.Add(txtTest)
Next
End Sub
On 30 Apr, 16:55, "Ray Costanzo" <my first name at lane 34 dot
commercialwrote:
It's possible that what you're trying to do can be done with an
entirely
different approach. If you want to post snippets of ASPX and .VB that
would
be enough for us to duplicate what you're doing, maybe someone could
offer
some alternate routes if they'd seem appropriate.
Ray at work
<mj.redfox...@gmail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
Hmmmm. The textboxes (there are a few of them created by a FOR...NEXT
loop) are actually behaving VERY weirdly, using your suggestion I can
now assign a text value to all but the first two, even though the
loop
handles them all identically!!????
I'll have another look tomorrow and then report back as this may be
useful for other people in the future. I wonder if dynamic generated
form elements are just unstable in general?- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

May 1 '07 #10

P: n/a
Someone has just told me that I may need to add the textboxes to the
form collection in the Page_Init routine, rather than the Page_Load.

HOWEVER...having just tried this by changing the above code to handle
Page_Init instead, this gives another problem...although it still
recognizes a postback, and even that DropDownList1 is the
'__EVENTTARGET', it can no longer get the VALUE submitted by
DropDownList1 (whereas in Page_Load it can) - and getting that value
is absolutely critical to how this page works. So I'm not sure that
Page_Init is the answer...I'll keep trying though :(
On 1 May, 12:27, mj.redfox...@gmail.com wrote:
I've tried it from 0 though for testing purposes, again couldn't set
the text for that textbox but could for all the ones from 2 onwards.

On 1 May, 09:19, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
cntCount will never be 0 as you start it from 1.
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com-Local franchises available
<mj.redfox...@gmail.comwrote in message
news:11**********************@c35g2000hsg.googlegr oups.com...
QUICK ADD: For some reason, in the above I've accidentally deleted the
line where if 'Computer' is selected in the drop-down list, then
strTemplate is set to "Computer". Sorry about that, the important
point in the above is that the line that adds the text to textbox
txtLeft2 works fine, so I just need to figure out what is so 'special'
about textboxes 1 and 2...
On 1 May, 08:31, mj.redfox...@gmail.com wrote:
>OK, here's the code behind page in full. I didn't post this originally
>as it's in a very 'quick and dirty' state at the moment, and needs
>tidied, commented and the variables renamed...but this is what I've
>been working with It basically adds a variable number of table cells
>and textboxes within them, based on the value of 'intAttributes'.
>Using this, for some reason I can only set properties of textboxes
>txtLeft2 - txtLeft8 (or whatever the upper limit is) - any attempt to
>programmatically change the initial text in textboxes txtTest0 or
>txtTest1 has no effect. Very, very strange.
>Partial Class _ShowData
> Inherits System.Web.UI.Page
> Sub Page_Load(ByVal Sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
> Dim strTemplate As String
> Dim intAttributes As Integer
> Dim txtTest As TextBox
> Dim trTest As TableRow
> Dim tdTest As TableCell
> Dim cntCount As Integer
> strTemplate = ""
> intAttributes = 1
> If Page.IsPostBack Then
> If Page.Request.Params.Get("__EVENTTARGET") =
>"DropDownList1" Then
> strTemplate = DropDownList1.Text
> Select Case DropDownList1.Text
> Case "Computer"
> intAttributes = 8
> Case "Generic"
> intAttributes = 6
> End Select
> End If
> End If
> For cntCount = 1 To intAttributes
> trTest = New TableRow
> trTest.ID = "trSpecification" + cntCount.ToString
> Page.FindControl("tblSpecification").Controls.Add( trTest)
> tdTest = New TableCell
> tdTest.ID = "tdSpecificationLeft" + cntCount.ToString
> Page.FindControl("trSpecification" +
>cntCount.ToString).Controls.Add(tdTest)
> tdTest = New TableCell
> tdTest.ID = "tdSpecificationRight" + cntCount.ToString
> Page.FindControl("trSpecification" +
>cntCount.ToString).Controls.Add(tdTest)
> txtTest = New TextBox
> txtTest.ID = "txtLeft" + cntCount.ToString
> If strTemplate = "Computer" Then
> If cntCount = 0 Then
> txtTest.Text = "Test Text 0"
> End If
> If cntCount = 1 Then
> txtTest.Text = "Test Text 1"
> End If
> If cntCount = 2 Then
> txtTest.Text = "Test Text 2"
> End If
> End If
> Page.FindControl("tdSpecificationLeft" +
>cntCount.ToString).Controls.Add(txtTest)
> txtTest = New TextBox
> txtTest.ID = "txtRight" + cntCount.ToString
> Page.FindControl("tdSpecificationRight" +
>cntCount.ToString).Controls.Add(txtTest)
> Next
> End Sub
>On 30 Apr, 16:55, "Ray Costanzo" <my first name at lane 34 dot
>commercialwrote:
It's possible that what you're trying to do can be done with an
entirely
different approach. If you want to post snippets of ASPX and .VB that
would
be enough for us to duplicate what you're doing, maybe someone could
offer
some alternate routes if they'd seem appropriate.
Ray at work
<mj.redfox...@gmail.comwrote in message
>news:11*********************@p77g2000hsh.googlegr oups.com...
Hmmmm. The textboxes (there are a few of them created by a FOR...NEXT
loop) are actually behaving VERY weirdly, using your suggestion I can
now assign a text value to all but the first two, even though the
loop
handles them all identically!!????
I'll have another look tomorrow and then report back as this may be
useful for other people in the future. I wonder if dynamic generated
form elements are just unstable in general?- Hide quoted text -
- Show quoted text -- Hide quoted text -
>- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

May 1 '07 #11

P: n/a
Something else I have just noticed... you can test around this.

You have two if statements around your switch case. If you cannot get past
either of these if statements, then your intAttributes will never be more
than one.

So, ignore the case statement, set specifically intAttributes to a value
afterwards, see what happens. In fact, I was not aware DropDownList had a
..Text value. I always use either .SelectedText, .SelectedValue or
..SelectedIndex. If I am correct, then your intAtrribute value will not be
being set.

You really need to step through your code to see if the values you expect
are correct at certain points. Especially in the loop. Just re-reading your
code again, if I am correct on the DropDownList, then that will ensure that
0, 1 and 2 settings are not being set, as strTemplate will be an empty
string.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
<mj**********@gmail.comwrote in message
news:11**********************@y5g2000hsa.googlegro ups.com...
Someone has just told me that I may need to add the textboxes to the
form collection in the Page_Init routine, rather than the Page_Load.

HOWEVER...having just tried this by changing the above code to handle
Page_Init instead, this gives another problem...although it still
recognizes a postback, and even that DropDownList1 is the
'__EVENTTARGET', it can no longer get the VALUE submitted by
DropDownList1 (whereas in Page_Load it can) - and getting that value
is absolutely critical to how this page works. So I'm not sure that
Page_Init is the answer...I'll keep trying though :(
On 1 May, 12:27, mj.redfox...@gmail.com wrote:
>I've tried it from 0 though for testing purposes, again couldn't set
the text for that textbox but could for all the ones from 2 onwards.

On 1 May, 09:19, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
cntCount will never be 0 as you start it from 1.
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com-Local franchises available
<mj.redfox...@gmail.comwrote in message
>news:11**********************@c35g2000hsg.googleg roups.com...
QUICK ADD: For some reason, in the above I've accidentally deleted
the
line where if 'Computer' is selected in the drop-down list, then
strTemplate is set to "Computer". Sorry about that, the important
point in the above is that the line that adds the text to textbox
txtLeft2 works fine, so I just need to figure out what is so
'special'
about textboxes 1 and 2...
On 1 May, 08:31, mj.redfox...@gmail.com wrote:
OK, here's the code behind page in full. I didn't post this
originally
as it's in a very 'quick and dirty' state at the moment, and needs
tidied, commented and the variables renamed...but this is what I've
been working with It basically adds a variable number of table cells
and textboxes within them, based on the value of 'intAttributes'.
Using this, for some reason I can only set properties of textboxes
txtLeft2 - txtLeft8 (or whatever the upper limit is) - any attempt
to
programmatically change the initial text in textboxes txtTest0 or
txtTest1 has no effect. Very, very strange.
>Partial Class _ShowData
Inherits System.Web.UI.Page
> Sub Page_Load(ByVal Sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
> Dim strTemplate As String
Dim intAttributes As Integer
Dim txtTest As TextBox
Dim trTest As TableRow
Dim tdTest As TableCell
Dim cntCount As Integer
> strTemplate = ""
intAttributes = 1
> If Page.IsPostBack Then
If Page.Request.Params.Get("__EVENTTARGET") =
"DropDownList1" Then
strTemplate = DropDownList1.Text
Select Case DropDownList1.Text
Case "Computer"
intAttributes = 8
Case "Generic"
intAttributes = 6
End Select
End If
End If
> For cntCount = 1 To intAttributes
> trTest = New TableRow
trTest.ID = "trSpecification" + cntCount.ToString

Page.FindControl("tblSpecification").Controls.Add (trTest)
> tdTest = New TableCell
tdTest.ID = "tdSpecificationLeft" + cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)
> tdTest = New TableCell
tdTest.ID = "tdSpecificationRight" + cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)
> txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
If strTemplate = "Computer" Then
If cntCount = 0 Then
txtTest.Text = "Test Text 0"
End If
If cntCount = 1 Then
txtTest.Text = "Test Text 1"
End If
If cntCount = 2 Then
txtTest.Text = "Test Text 2"
End If
End If
Page.FindControl("tdSpecificationLeft" +
cntCount.ToString).Controls.Add(txtTest)
> txtTest = New TextBox
txtTest.ID = "txtRight" + cntCount.ToString
Page.FindControl("tdSpecificationRight" +
cntCount.ToString).Controls.Add(txtTest)
> Next
> End Sub
>On 30 Apr, 16:55, "Ray Costanzo" <my first name at lane 34 dot
>commercialwrote:
It's possible that what you're trying to do can be done with an
entirely
different approach. If you want to post snippets of ASPX and .VB
that
would
be enough for us to duplicate what you're doing, maybe someone
could
offer
some alternate routes if they'd seem appropriate.
Ray at work
<mj.redfox...@gmail.comwrote in message
>news:11*********************@p77g2000hsh.googlegr oups.com...
Hmmmm. The textboxes (there are a few of them created by a
FOR...NEXT
loop) are actually behaving VERY weirdly, using your suggestion
I can
now assign a text value to all but the first two, even though
the
loop
handles them all identically!!????
I'll have another look tomorrow and then report back as this may
be
useful for other people in the future. I wonder if dynamic
generated
form elements are just unstable in general?- Hide quoted text -
- Show quoted text -- Hide quoted text -
>- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -


May 1 '07 #12

P: n/a
Hi David

Thanks for replying, you're absolutely correct about those two key
'checkpoints' in the code; the bottom line after doing all sorts of
tests appears to be that if I have the above code in Page_Init and
hard-code the number of textboxes, plus their text values, then it
works, but I can't get the postback submission from the drop down list
(as obviously this info is not available at Page_Init) - if I put the
code in Page_Load, then I DO get the drop-down list postback, but I
believe by this time it's then too late to add the dynamic controls to
the page, as this needs to be done at Page_Init. I guess this is
what's referred to as 'Catch 22'!

Looks like I'm going to have to re-write this whole thing some other
way, which is a real shame as I would have loved to have got this
working dynamically, plus it would have been better coding practice.

It's a classic example of being unable to achieve something in .NET
that would have taken fifteen minutes flat in Classic ASP and
Javascript - very frustrating.
On 1 May, 16:11, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
Something else I have just noticed... you can test around this.

You have two if statements around your switch case. If you cannot get past
either of these if statements, then your intAttributes will never be more
than one.

So, ignore the case statement, set specifically intAttributes to a value
afterwards, see what happens. In fact, I was not aware DropDownList had a
.Text value. I always use either .SelectedText, .SelectedValue or
.SelectedIndex. If I am correct, then your intAtrribute value will not be
being set.

You really need to step through your code to see if the values you expect
are correct at certain points. Especially in the loop. Just re-reading your
code again, if I am correct on the DropDownList, then that will ensure that
0, 1 and 2 settings are not being set, as strTemplate will be an empty
string.
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com- Local franchises available

<mj.redfox...@gmail.comwrote in message

news:11**********************@y5g2000hsa.googlegro ups.com...
Someone has just told me that I may need to add the textboxes to the
form collection in the Page_Init routine, rather than the Page_Load.
HOWEVER...having just tried this by changing the above code to handle
Page_Init instead, this gives another problem...although it still
recognizes a postback, and even that DropDownList1 is the
'__EVENTTARGET', it can no longer get the VALUE submitted by
DropDownList1 (whereas in Page_Load it can) - and getting that value
is absolutely critical to how this page works. So I'm not sure that
Page_Init is the answer...I'll keep trying though :(
On 1 May, 12:27, mj.redfox...@gmail.com wrote:
I've tried it from 0 though for testing purposes, again couldn't set
the text for that textbox but could for all the ones from 2 onwards.
On 1 May, 09:19, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
cntCount will never be 0 as you start it from 1.
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com-Localfranchises available
<mj.redfox...@gmail.comwrote in message
news:11**********************@c35g2000hsg.googlegr oups.com...
QUICK ADD: For some reason, in the above I've accidentally deleted
the
line where if 'Computer' is selected in the drop-down list, then
strTemplate is set to "Computer". Sorry about that, the important
point in the above is that the line that adds the text to textbox
txtLeft2 works fine, so I just need to figure out what is so
'special'
about textboxes 1 and 2...
On 1 May, 08:31, mj.redfox...@gmail.com wrote:
>OK, here's the code behind page in full. I didn't post this
>originally
>as it's in a very 'quick and dirty' state at the moment, and needs
>tidied, commented and the variables renamed...but this is what I've
>been working with It basically adds a variable number of table cells
>and textboxes within them, based on the value of 'intAttributes'.
>Using this, for some reason I can only set properties of textboxes
>txtLeft2 - txtLeft8 (or whatever the upper limit is) - any attempt
>to
>programmatically change the initial text in textboxes txtTest0 or
>txtTest1 has no effect. Very, very strange.
>Partial Class _ShowData
> Inherits System.Web.UI.Page
> Sub Page_Load(ByVal Sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
> Dim strTemplate As String
> Dim intAttributes As Integer
> Dim txtTest As TextBox
> Dim trTest As TableRow
> Dim tdTest As TableCell
> Dim cntCount As Integer
> strTemplate = ""
> intAttributes = 1
> If Page.IsPostBack Then
> If Page.Request.Params.Get("__EVENTTARGET") =
>"DropDownList1" Then
> strTemplate = DropDownList1.Text
> Select Case DropDownList1.Text
> Case "Computer"
> intAttributes = 8
> Case "Generic"
> intAttributes = 6
> End Select
> End If
> End If
> For cntCount = 1 To intAttributes
> trTest = New TableRow
> trTest.ID = "trSpecification" + cntCount.ToString
>Page.FindControl("tblSpecification").Controls.Add (trTest)
> tdTest = New TableCell
> tdTest.ID = "tdSpecificationLeft" + cntCount.ToString
> Page.FindControl("trSpecification" +
>cntCount.ToString).Controls.Add(tdTest)
> tdTest = New TableCell
> tdTest.ID = "tdSpecificationRight" + cntCount.ToString
> Page.FindControl("trSpecification" +
>cntCount.ToString).Controls.Add(tdTest)
> txtTest = New TextBox
> txtTest.ID = "txtLeft" + cntCount.ToString
> If strTemplate = "Computer" Then
> If cntCount = 0 Then
> txtTest.Text = "Test Text 0"
> End If
> If cntCount = 1 Then
> txtTest.Text = "Test Text 1"
> End If
> If cntCount = 2 Then
> txtTest.Text = "Test Text 2"
> End If
> End If
> Page.FindControl("tdSpecificationLeft" +
>cntCount.ToString).Controls.Add(txtTest)
> txtTest = New TextBox
> txtTest.ID = "txtRight" + cntCount.ToString
> Page.FindControl("tdSpecificationRight" +
>cntCount.ToString).Controls.Add(txtTest)
> Next
> End Sub
>On 30 Apr, 16:55, "Ray Costanzo" <my first name at lane 34 dot
>commercialwrote:
It's possible that what you're trying to do can be done with an
entirely
different approach. If you want to post snippets of ASPX and .VB
that
would
be enough for us to duplicate what you're doing, maybe someone
could
offer
some alternate routes if they'd seem appropriate.
Ray at work
<mj.redfox...@gmail.comwrote in message
>news:11*********************@p77g2000hsh.googlegr oups.com...
Hmmmm. The textboxes (there are a few of them created by a
FOR...NEXT
loop) are actually behaving VERY weirdly, using your suggestion
I can
now assign a text value to all but the first two, even though
the
loop
handles them all identically!!????
I'll have another look tomorrow and then report back as this may
be
useful for other people in the future. I wonder if dynamic
generated
form elements are just unstable in general?- Hide quoted text -
- Show quoted text -- Hide quoted text -
>- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

May 1 '07 #13

P: n/a
Can't you create the textboxes prior to reading the dropdown?

create text box
read dropdown
enable/disable/assign values to textbox based on drop down
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

<mj**********@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
Hi David

Thanks for replying, you're absolutely correct about those two key
'checkpoints' in the code; the bottom line after doing all sorts of
tests appears to be that if I have the above code in Page_Init and
hard-code the number of textboxes, plus their text values, then it
works, but I can't get the postback submission from the drop down list
(as obviously this info is not available at Page_Init) - if I put the
code in Page_Load, then I DO get the drop-down list postback, but I
believe by this time it's then too late to add the dynamic controls to
the page, as this needs to be done at Page_Init. I guess this is
what's referred to as 'Catch 22'!

Looks like I'm going to have to re-write this whole thing some other
way, which is a real shame as I would have loved to have got this
working dynamically, plus it would have been better coding practice.

It's a classic example of being unable to achieve something in .NET
that would have taken fifteen minutes flat in Classic ASP and
Javascript - very frustrating.
On 1 May, 16:11, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
>Something else I have just noticed... you can test around this.

You have two if statements around your switch case. If you cannot get
past
either of these if statements, then your intAttributes will never be more
than one.

So, ignore the case statement, set specifically intAttributes to a value
afterwards, see what happens. In fact, I was not aware DropDownList had a
.Text value. I always use either .SelectedText, .SelectedValue or
.SelectedIndex. If I am correct, then your intAtrribute value will not be
being set.

You really need to step through your code to see if the values you expect
are correct at certain points. Especially in the loop. Just re-reading
your
code again, if I am correct on the DropDownList, then that will ensure
that
0, 1 and 2 settings are not being set, as strTemplate will be an empty
string.
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com- Local franchises available

<mj.redfox...@gmail.comwrote in message

news:11**********************@y5g2000hsa.googlegr oups.com...
Someone has just told me that I may need to add the textboxes to the
form collection in the Page_Init routine, rather than the Page_Load.
HOWEVER...having just tried this by changing the above code to handle
Page_Init instead, this gives another problem...although it still
recognizes a postback, and even that DropDownList1 is the
'__EVENTTARGET', it can no longer get the VALUE submitted by
DropDownList1 (whereas in Page_Load it can) - and getting that value
is absolutely critical to how this page works. So I'm not sure that
Page_Init is the answer...I'll keep trying though :(
On 1 May, 12:27, mj.redfox...@gmail.com wrote:
I've tried it from 0 though for testing purposes, again couldn't set
the text for that textbox but could for all the ones from 2 onwards.
>On 1 May, 09:19, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
cntCount will never be 0 as you start it from 1.
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com-Localfranchises available
<mj.redfox...@gmail.comwrote in message
>news:11**********************@c35g2000hsg.googleg roups.com...
QUICK ADD: For some reason, in the above I've accidentally deleted
the
line where if 'Computer' is selected in the drop-down list, then
strTemplate is set to "Computer". Sorry about that, the important
point in the above is that the line that adds the text to textbox
txtLeft2 works fine, so I just need to figure out what is so
'special'
about textboxes 1 and 2...
On 1 May, 08:31, mj.redfox...@gmail.com wrote:
OK, here's the code behind page in full. I didn't post this
originally
as it's in a very 'quick and dirty' state at the moment, and
needs
tidied, commented and the variables renamed...but this is what
I've
been working with It basically adds a variable number of table
cells
and textboxes within them, based on the value of 'intAttributes'.
Using this, for some reason I can only set properties of
textboxes
txtLeft2 - txtLeft8 (or whatever the upper limit is) - any
attempt
to
programmatically change the initial text in textboxes txtTest0 or
txtTest1 has no effect. Very, very strange.
>Partial Class _ShowData
Inherits System.Web.UI.Page
> Sub Page_Load(ByVal Sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
> Dim strTemplate As String
Dim intAttributes As Integer
Dim txtTest As TextBox
Dim trTest As TableRow
Dim tdTest As TableCell
Dim cntCount As Integer
> strTemplate = ""
intAttributes = 1
> If Page.IsPostBack Then
If Page.Request.Params.Get("__EVENTTARGET") =
"DropDownList1" Then
strTemplate = DropDownList1.Text
Select Case DropDownList1.Text
Case "Computer"
intAttributes = 8
Case "Generic"
intAttributes = 6
End Select
End If
End If
> For cntCount = 1 To intAttributes
> trTest = New TableRow
trTest.ID = "trSpecification" + cntCount.ToString
>Page.FindControl("tblSpecification").Controls.Add (trTest)
> tdTest = New TableCell
tdTest.ID = "tdSpecificationLeft" + cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)
> tdTest = New TableCell
tdTest.ID = "tdSpecificationRight" +
cntCount.ToString
Page.FindControl("trSpecification" +
cntCount.ToString).Controls.Add(tdTest)
> txtTest = New TextBox
txtTest.ID = "txtLeft" + cntCount.ToString
If strTemplate = "Computer" Then
If cntCount = 0 Then
txtTest.Text = "Test Text 0"
End If
If cntCount = 1 Then
txtTest.Text = "Test Text 1"
End If
If cntCount = 2 Then
txtTest.Text = "Test Text 2"
End If
End If
Page.FindControl("tdSpecificationLeft" +
cntCount.ToString).Controls.Add(txtTest)
> txtTest = New TextBox
txtTest.ID = "txtRight" + cntCount.ToString
Page.FindControl("tdSpecificationRight" +
cntCount.ToString).Controls.Add(txtTest)
> Next
> End Sub
>On 30 Apr, 16:55, "Ray Costanzo" <my first name at lane 34 dot
>commercialwrote:
It's possible that what you're trying to do can be done with an
entirely
different approach. If you want to post snippets of ASPX and
.VB
that
would
be enough for us to duplicate what you're doing, maybe someone
could
offer
some alternate routes if they'd seem appropriate.
Ray at work
<mj.redfox...@gmail.comwrote in message
>news:11*********************@p77g2000hsh.googlegr oups.com...
Hmmmm. The textboxes (there are a few of them created by a
FOR...NEXT
loop) are actually behaving VERY weirdly, using your
suggestion
I can
now assign a text value to all but the first two, even though
the
loop
handles them all identically!!????
I'll have another look tomorrow and then report back as this
may
be
useful for other people in the future. I wonder if dynamic
generated
form elements are just unstable in general?- Hide quoted
text -
- Show quoted text -- Hide quoted text -
>- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -
>- Show quoted text -- Hide quoted text -

- Show quoted text -


May 1 '07 #14

P: n/a
Not really, because the value of the dropdown (readable in Page_Load)
determines how many textboxes I need to dynamically create (in
Page_Init). I'm struggling to see a way around this to be honest.
On 1 May, 16:44, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
Can't you create the textboxes prior to reading the dropdown?

create text box
read dropdown
enable/disable/assign values to textbox based on drop down

--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com- Local franchises available

<mj.redfox...@gmail.comwrote in message

news:11**********************@q75g2000hsh.googlegr oups.com...
Hi David
Thanks for replying, you're absolutely correct about those two key
'checkpoints' in the code; the bottom line after doing all sorts of
tests appears to be that if I have the above code in Page_Init and
hard-code the number of textboxes, plus their text values, then it
works, but I can't get the postback submission from the drop down list
(as obviously this info is not available at Page_Init) - if I put the
code in Page_Load, then I DO get the drop-down list postback, but I
believe by this time it's then too late to add the dynamic controls to
the page, as this needs to be done at Page_Init. I guess this is
what's referred to as 'Catch 22'!
Looks like I'm going to have to re-write this whole thing some other
way, which is a real shame as I would have loved to have got this
working dynamically, plus it would have been better coding practice.
It's a classic example of being unable to achieve something in .NET
that would have taken fifteen minutes flat in Classic ASP and
Javascript - very frustrating.
On 1 May, 16:11, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
Something else I have just noticed... you can test around this.
You have two if statements around your switch case. If you cannot get
past
either of these if statements, then your intAttributes will never be more
than one.
So, ignore the case statement, set specifically intAttributes to a value
afterwards, see what happens. In fact, I was not aware DropDownList had a
.Text value. I always use either .SelectedText, .SelectedValue or
.SelectedIndex. If I am correct, then your intAtrribute value will not be
being set.
You really need to step through your code to see if the values you expect
are correct at certain points. Especially in the loop. Just re-reading
your
code again, if I am correct on the DropDownList, then that will ensure
that
0, 1 and 2 settings are not being set, as strTemplate will be an empty
string.
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com-Local franchises available
<mj.redfox...@gmail.comwrote in message
>news:11**********************@y5g2000hsa.googlegr oups.com...
Someone has just told me that I may need to add the textboxes to the
form collection in the Page_Init routine, rather than the Page_Load.
HOWEVER...having just tried this by changing the above code to handle
Page_Init instead, this gives another problem...although it still
recognizes a postback, and even that DropDownList1 is the
'__EVENTTARGET', it can no longer get the VALUE submitted by
DropDownList1 (whereas in Page_Load it can) - and getting that value
is absolutely critical to how this page works. So I'm not sure that
Page_Init is the answer...I'll keep trying though :(
On 1 May, 12:27, mj.redfox...@gmail.com wrote:
I've tried it from 0 though for testing purposes, again couldn't set
the text for that textbox but could for all the ones from 2 onwards.
On 1 May, 09:19, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
cntCount will never be 0 as you start it from 1.
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com-Localfranchisesavailable
<mj.redfox...@gmail.comwrote in message
news:11**********************@c35g2000hsg.googlegr oups.com...
QUICK ADD: For some reason, in the above I've accidentally deleted
the
line where if 'Computer' is selected in the drop-down list, then
strTemplate is set to "Computer". Sorry about that, the important
point in the above is that the line that adds the text to textbox
txtLeft2 works fine, so I just need to figure out what is so
'special'
about textboxes 1 and 2...
On 1 May, 08:31, mj.redfox...@gmail.com wrote:
>OK, here's the code behind page in full. I didn't post this
>originally
>as it's in a very 'quick and dirty' state at the moment, and
>needs
>tidied, commented and the variables renamed...but this is what
>I've
>been working with It basically adds a variable number of table
>cells
>and textboxes within them, based on the value of 'intAttributes'.
>Using this, for some reason I can only set properties of
>textboxes
>txtLeft2 - txtLeft8 (or whatever the upper limit is) - any
>attempt
>to
>programmatically change the initial text in textboxes txtTest0 or
>txtTest1 has no effect. Very, very strange.
>Partial Class _ShowData
> Inherits System.Web.UI.Page
> Sub Page_Load(ByVal Sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
> Dim strTemplate As String
> Dim intAttributes As Integer
> Dim txtTest As TextBox
> Dim trTest As TableRow
> Dim tdTest As TableCell
> Dim cntCount As Integer
> strTemplate = ""
> intAttributes = 1
> If Page.IsPostBack Then
> If Page.Request.Params.Get("__EVENTTARGET") =
>"DropDownList1" Then
> strTemplate = DropDownList1.Text
> Select Case DropDownList1.Text
> Case "Computer"
> intAttributes = 8
> Case "Generic"
> intAttributes = 6
> End Select
> End If
> End If
> For cntCount = 1 To intAttributes
> trTest = New TableRow
> trTest.ID = "trSpecification" + cntCount.ToString
>Page.FindControl("tblSpecification").Controls.Add (trTest)
> tdTest = New TableCell
> tdTest.ID = "tdSpecificationLeft" + cntCount.ToString
> Page.FindControl("trSpecification" +
>cntCount.ToString).Controls.Add(tdTest)
> tdTest = New TableCell
> tdTest.ID = "tdSpecificationRight" +
>cntCount.ToString
> Page.FindControl("trSpecification" +
>cntCount.ToString).Controls.Add(tdTest)
> txtTest = New TextBox
> txtTest.ID = "txtLeft" + cntCount.ToString
> If strTemplate = "Computer" Then
> If cntCount = 0 Then
> txtTest.Text = "Test Text 0"
> End If
> If cntCount = 1 Then
> txtTest.Text = "Test Text 1"
> End If
> If cntCount = 2 Then
> txtTest.Text = "Test Text 2"
> End If
> End If
> Page.FindControl("tdSpecificationLeft" +
>cntCount.ToString).Controls.Add(txtTest)
> txtTest = New TextBox
> txtTest.ID = "txtRight" + cntCount.ToString
> Page.FindControl("tdSpecificationRight" +
>cntCount.ToString).Controls.Add(txtTest)
> Next
> End Sub
>On 30 Apr, 16:55, "Ray Costanzo" <my first name at lane 34 dot
>commercialwrote:
It's possible that what you're trying to do can be done with an
entirely
different approach. If you want to post snippets of ASPX and
.VB
that
would
be enough for us to duplicate what you're doing, maybe someone
could
offer
some alternate routes if they'd seem appropriate.
Ray at work
<mj.redfox...@gmail.comwrote in message
>news:11*********************@p77g2000hsh.googlegr oups.com...
Hmmmm. The textboxes (there are a few of them created by a
FOR...NEXT
loop) are actually behaving VERY weirdly, using your
suggestion
I can
now assign a text value to all but the first two, even though
the
loop
handles them all identically!!????
I'll have another look tomorrow and then report back as this
may
be
useful for other people in the future. I wonder if dynamic
generated
form elements are just unstable in general?- Hide quoted
text -
- Show quoted text -- Hide quoted text -
>- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

May 2 '07 #15

P: n/a
I think I may have just stumbled on the answer. It appears the code
needs to be in a DropDownList1_SelectedIndexChanged routine - the
reason I hadn't done this previously was that everything else I'd read
suggested I needed to insert the code in Page_Init - ah well, upwards
and onwards...and thanks for your help along the way guys.
On 2 May, 08:00, mj.redfox...@gmail.com wrote:
Not really, because the value of the dropdown (readable in Page_Load)
determines how many textboxes I need to dynamically create (in
Page_Init). I'm struggling to see a way around this to be honest.

On 1 May, 16:44, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
Can't you create the textboxes prior to reading the dropdown?
create text box
read dropdown
enable/disable/assign values to textbox based on drop down
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com-Local franchises available
<mj.redfox...@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
Hi David
Thanks for replying, you're absolutely correct about those two key
'checkpoints' in the code; the bottom line after doing all sorts of
tests appears to be that if I have the above code in Page_Init and
hard-code the number of textboxes, plus their text values, then it
works, but I can't get the postback submission from the drop down list
(as obviously this info is not available at Page_Init) - if I put the
code in Page_Load, then I DO get the drop-down list postback, but I
believe by this time it's then too late to add the dynamic controls to
the page, as this needs to be done at Page_Init. I guess this is
what's referred to as 'Catch 22'!
Looks like I'm going to have to re-write this whole thing some other
way, which is a real shame as I would have loved to have got this
working dynamically, plus it would have been better coding practice.
It's a classic example of being unable to achieve something in .NET
that would have taken fifteen minutes flat in Classic ASP and
Javascript - very frustrating.
On 1 May, 16:11, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
>Something else I have just noticed... you can test around this.
>You have two if statements around your switch case. If you cannot get
>past
>either of these if statements, then your intAttributes will never bemore
>than one.
>So, ignore the case statement, set specifically intAttributes to a value
>afterwards, see what happens. In fact, I was not aware DropDownList had a
>.Text value. I always use either .SelectedText, .SelectedValue or
>.SelectedIndex. If I am correct, then your intAtrribute value will not be
>being set.
>You really need to step through your code to see if the values you expect
>are correct at certain points. Especially in the loop. Just re-reading
>your
>code again, if I am correct on the DropDownList, then that will ensure
>that
>0, 1 and 2 settings are not being set, as strTemplate will be an empty
>string.
>--
>Best regards,
>Dave Colliver.http://www.AshfieldFOCUS.com
>~~http://www.FOCUSPortals.com-Localfranchises available
><mj.redfox...@gmail.comwrote in message
>>news:11**********************@y5g2000hsa.googleg roups.com...
Someone has just told me that I may need to add the textboxes to the
form collection in the Page_Init routine, rather than the Page_Load.
HOWEVER...having just tried this by changing the above code to handle
Page_Init instead, this gives another problem...although it still
recognizes a postback, and even that DropDownList1 is the
'__EVENTTARGET', it can no longer get the VALUE submitted by
DropDownList1 (whereas in Page_Load it can) - and getting that value
is absolutely critical to how this page works. So I'm not sure that
Page_Init is the answer...I'll keep trying though :(
On 1 May, 12:27, mj.redfox...@gmail.com wrote:
>I've tried it from 0 though for testing purposes, again couldn't set
>the text for that textbox but could for all the ones from 2 onwards.
>On 1 May, 09:19, "David" <david.colliver.N...@revilloc.REMOVETHIS..com>
>wrote:
cntCount will never be 0 as you start it from 1.
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com-Localfranchisesavailable
<mj.redfox...@gmail.comwrote in message
>news:11**********************@c35g2000hsg.googleg roups.com...
QUICK ADD: For some reason, in the above I've accidentally deleted
the
line where if 'Computer' is selected in the drop-down list, then
strTemplate is set to "Computer". Sorry about that, the important
point in the above is that the line that adds the text to textbox
txtLeft2 works fine, so I just need to figure out what is so
'special'
about textboxes 1 and 2...
On 1 May, 08:31, mj.redfox...@gmail.com wrote:
>OK, here's the code behind page in full. I didn't post this
>originally
>as it's in a very 'quick and dirty' state at the moment, and
>needs
>tidied, commented and the variables renamed...but this is what
>I've
>been working with It basically adds a variable number of table
>cells
>and textboxes within them, based on the value of 'intAttributes'.
>Using this, for some reason I can only set properties of
>textboxes
>txtLeft2 - txtLeft8 (or whatever the upper limit is) - any
>attempt
>to
>programmatically change the initial text in textboxes txtTest0 or
>txtTest1 has no effect. Very, very strange.
>Partial Class _ShowData
> Inherits System.Web.UI.Page
> Sub Page_Load(ByVal Sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
> Dim strTemplate As String
> Dim intAttributes As Integer
> Dim txtTest As TextBox
> Dim trTest As TableRow
> Dim tdTest As TableCell
> Dim cntCount As Integer
> strTemplate = ""
> intAttributes = 1
> If Page.IsPostBack Then
> If Page.Request.Params.Get("__EVENTTARGET") =
>"DropDownList1" Then
> strTemplate = DropDownList1.Text
> Select Case DropDownList1.Text
> Case "Computer"
> intAttributes = 8
> Case "Generic"
> intAttributes = 6
> End Select
> End If
> End If
> For cntCount = 1 To intAttributes
> trTest = New TableRow
> trTest.ID = "trSpecification" + cntCount.ToString
>Page.FindControl("tblSpecification").Controls.Add (trTest)
> tdTest = New TableCell
> tdTest.ID = "tdSpecificationLeft" + cntCount.ToString
> Page.FindControl("trSpecification" +
>cntCount.ToString).Controls.Add(tdTest)
> tdTest = New TableCell
> tdTest.ID = "tdSpecificationRight" +
>cntCount.ToString
> Page.FindControl("trSpecification" +
>cntCount.ToString).Controls.Add(tdTest)
> txtTest = New TextBox
> txtTest.ID = "txtLeft" + cntCount.ToString
> If strTemplate = "Computer" Then
> If cntCount = 0 Then
> txtTest.Text = "Test Text 0"
> End If
> If cntCount = 1 Then
> txtTest.Text = "Test Text 1"
> End If
> If cntCount = 2 Then
> txtTest.Text = "Test Text 2"
> End If
> End If
> Page.FindControl("tdSpecificationLeft" +
>cntCount.ToString).Controls.Add(txtTest)
> txtTest = New TextBox
> txtTest.ID = "txtRight" + cntCount.ToString
> Page.FindControl("tdSpecificationRight" +
>cntCount.ToString).Controls.Add(txtTest)
> Next
> End Sub
>On 30 Apr, 16:55, "Ray Costanzo" <my first name at lane 34 dot
>commercialwrote:
It's possible that what you're trying to do can be done with an
entirely
different approach. If you want to post snippets of ASPX and
.VB
that
would
be enough for us to duplicate what you're doing, maybe someone
could
offer
some alternate routes if they'd seem appropriate.
Ray at work
<mj.redfox...@gmail.comwrote in message
>news:11*********************@p77g2000hsh.googlegr oups.com...
Hmmmm. The textboxes (there are a few of them created bya
FOR...NEXT
loop) are actually behaving VERY weirdly, using your
suggestion
I can
now assign a text value to all but the first two, even though
the
loop
handles them all identically!!????
I'll have another look tomorrow and then report back as this
may
be
useful for other people in the future. I wonder if dynamic
generated
form elements are just

...

read more - Hide quoted text -

- Show quoted text -

May 2 '07 #16

P: n/a
Put the code in a seperate function. Get your selectedindexchanged to call
that function. That way, you can call the function any other time as well
(i.e. what happens when no selectedindexchanged event occurs, for example,
initial load of the page).

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
<mj**********@gmail.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
I think I may have just stumbled on the answer. It appears the code
needs to be in a DropDownList1_SelectedIndexChanged routine - the
reason I hadn't done this previously was that everything else I'd read
suggested I needed to insert the code in Page_Init - ah well, upwards
and onwards...and thanks for your help along the way guys.
On 2 May, 08:00, mj.redfox...@gmail.com wrote:
Not really, because the value of the dropdown (readable in Page_Load)
determines how many textboxes I need to dynamically create (in
Page_Init). I'm struggling to see a way around this to be honest.

On 1 May, 16:44, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
Can't you create the textboxes prior to reading the dropdown?
create text box
read dropdown
enable/disable/assign values to textbox based on drop down
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com-Local franchises available
<mj.redfox...@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
Hi David
Thanks for replying, you're absolutely correct about those two key
'checkpoints' in the code; the bottom line after doing all sorts of
tests appears to be that if I have the above code in Page_Init and
hard-code the number of textboxes, plus their text values, then it
works, but I can't get the postback submission from the drop down list
(as obviously this info is not available at Page_Init) - if I put the
code in Page_Load, then I DO get the drop-down list postback, but I
believe by this time it's then too late to add the dynamic controls to
the page, as this needs to be done at Page_Init. I guess this is
what's referred to as 'Catch 22'!
Looks like I'm going to have to re-write this whole thing some other
way, which is a real shame as I would have loved to have got this
working dynamically, plus it would have been better coding practice.
It's a classic example of being unable to achieve something in .NET
that would have taken fifteen minutes flat in Classic ASP and
Javascript - very frustrating.
On 1 May, 16:11, "David" <david.colliver.N...@revilloc.REMOVETHIS.com>
wrote:
>Something else I have just noticed... you can test around this.
>You have two if statements around your switch case. If you cannot get
>past
>either of these if statements, then your intAttributes will never be
>more
>than one.
>So, ignore the case statement, set specifically intAttributes to a
>value
>afterwards, see what happens. In fact, I was not aware DropDownList
>had a
>.Text value. I always use either .SelectedText, .SelectedValue or
>.SelectedIndex. If I am correct, then your intAtrribute value will
>not be
>being set.
>You really need to step through your code to see if the values you
>expect
>are correct at certain points. Especially in the loop. Just
>re-reading
>your
>code again, if I am correct on the DropDownList, then that will
>ensure
>that
>0, 1 and 2 settings are not being set, as strTemplate will be an
>empty
>string.
>--
>Best regards,
>Dave Colliver.http://www.AshfieldFOCUS.com
>~~http://www.FOCUSPortals.com-Localfranchises available
><mj.redfox...@gmail.comwrote in message
>>news:11**********************@y5g2000hsa.googleg roups.com...
Someone has just told me that I may need to add the textboxes to
the
form collection in the Page_Init routine, rather than the
Page_Load.
HOWEVER...having just tried this by changing the above code to
handle
Page_Init instead, this gives another problem...although it still
recognizes a postback, and even that DropDownList1 is the
'__EVENTTARGET', it can no longer get the VALUE submitted by
DropDownList1 (whereas in Page_Load it can) - and getting that
value
is absolutely critical to how this page works. So I'm not sure that
Page_Init is the answer...I'll keep trying though :(
On 1 May, 12:27, mj.redfox...@gmail.com wrote:
>I've tried it from 0 though for testing purposes, again couldn't
>set
>the text for that textbox but could for all the ones from 2
>onwards.
>On 1 May, 09:19, "David"
><david.colliver.N...@revilloc.REMOVETHIS.com>
>wrote:
cntCount will never be 0 as you start it from 1.
--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com-Localfranchisesavailable
<mj.redfox...@gmail.comwrote in message
>news:11**********************@c35g2000hsg.googleg roups.com...
QUICK ADD: For some reason, in the above I've accidentally
deleted
the
line where if 'Computer' is selected in the drop-down list,
then
strTemplate is set to "Computer". Sorry about that, the
important
point in the above is that the line that adds the text to
textbox
txtLeft2 works fine, so I just need to figure out what is so
'special'
about textboxes 1 and 2...
On 1 May, 08:31, mj.redfox...@gmail.com wrote:
>OK, here's the code behind page in full. I didn't post this
>originally
>as it's in a very 'quick and dirty' state at the moment, and
>needs
>tidied, commented and the variables renamed...but this is
>what
>I've
>been working with It basically adds a variable number of
>table
>cells
>and textboxes within them, based on the value of
>'intAttributes'.
>Using this, for some reason I can only set properties of
>textboxes
>txtLeft2 - txtLeft8 (or whatever the upper limit is) - any
>attempt
>to
>programmatically change the initial text in textboxes
>txtTest0 or
>txtTest1 has no effect. Very, very strange.
>Partial Class _ShowData
> Inherits System.Web.UI.Page
> Sub Page_Load(ByVal Sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
> Dim strTemplate As String
> Dim intAttributes As Integer
> Dim txtTest As TextBox
> Dim trTest As TableRow
> Dim tdTest As TableCell
> Dim cntCount As Integer
> strTemplate = ""
> intAttributes = 1
> If Page.IsPostBack Then
> If Page.Request.Params.Get("__EVENTTARGET") =
>"DropDownList1" Then
> strTemplate = DropDownList1.Text
> Select Case DropDownList1.Text
> Case "Computer"
> intAttributes = 8
> Case "Generic"
> intAttributes = 6
> End Select
> End If
> End If
> For cntCount = 1 To intAttributes
> trTest = New TableRow
> trTest.ID = "trSpecification" + cntCount.ToString
>Page.FindControl("tblSpecification").Controls.Add (trTest)
> tdTest = New TableCell
> tdTest.ID = "tdSpecificationLeft" +
>cntCount.ToString
> Page.FindControl("trSpecification" +
>cntCount.ToString).Controls.Add(tdTest)
> tdTest = New TableCell
> tdTest.ID = "tdSpecificationRight" +
>cntCount.ToString
> Page.FindControl("trSpecification" +
>cntCount.ToString).Controls.Add(tdTest)
> txtTest = New TextBox
> txtTest.ID = "txtLeft" + cntCount.ToString
> If strTemplate = "Computer" Then
> If cntCount = 0 Then
> txtTest.Text = "Test Text 0"
> End If
> If cntCount = 1 Then
> txtTest.Text = "Test Text 1"
> End If
> If cntCount = 2 Then
> txtTest.Text = "Test Text 2"
> End If
> End If
> Page.FindControl("tdSpecificationLeft" +
>cntCount.ToString).Controls.Add(txtTest)
> txtTest = New TextBox
> txtTest.ID = "txtRight" + cntCount.ToString
> Page.FindControl("tdSpecificationRight" +
>cntCount.ToString).Controls.Add(txtTest)
> Next
> End Sub
>On 30 Apr, 16:55, "Ray Costanzo" <my first name at lane 34
>dot
>commercialwrote:
It's possible that what you're trying to do can be done
with an
entirely
different approach. If you want to post snippets of ASPX
and
.VB
that
would
be enough for us to duplicate what you're doing, maybe
someone
could
offer
some alternate routes if they'd seem appropriate.
Ray at work
<mj.redfox...@gmail.comwrote in message
>news:11*********************@p77g2000hsh.googlegr oups.com...
Hmmmm. The textboxes (there are a few of them created by
a
FOR...NEXT
loop) are actually behaving VERY weirdly, using your
suggestion
I can
now assign a text value to all but the first two, even
though
the
loop
handles them all identically!!????
I'll have another look tomorrow and then report back as
this
may
be
useful for other people in the future. I wonder if
dynamic
generated
form elements are just

...

read more - Hide quoted text -

- Show quoted text -


May 2 '07 #17

This discussion thread is closed

Replies have been disabled for this discussion.