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

Discussion in 'ASP .Net' started by mj.redfox.mj@gmail.com, Apr 30, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. Ray Costanzo Guest

    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



    <> wrote in message
    news:...
    > 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
    Ray Costanzo, Apr 30, 2007
    #2
    1. Advertising

  3. Guest

    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
    commercial> wrote:
    > 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
    >
    > <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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, 2007
    #3
  4. Ray Costanzo Guest

    Not at all. :]

    Ray at work

    <> wrote in message
    news:...
    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
    commercial> wrote:
    > Your code works for me.\
    Ray Costanzo, Apr 30, 2007
    #4
  5. Guest

    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
    commercial> wrote:
    > Not at all. :]
    >
    > Ray at work
    >
    > <> wrote in message
    >
    > news:...
    > 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
    >
    >
    >
    > commercial> wrote:
    > > Your code works for me.\- Hide quoted text -

    >
    > - Show quoted text -
    , Apr 30, 2007
    #5
  6. Ray Costanzo Guest

    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

    <> wrote in message
    news:...
    > 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?
    Ray Costanzo, Apr 30, 2007
    #6
  7. Guest

    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
    commercial> wrote:
    > 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
    >
    > <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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, 2007
    #7
  8. Guest

    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, 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
    >
    >
    >
    > commercial> wrote:
    > > 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

    >
    > > <> wrote in message

    >
    > >news:...

    >
    > > > 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, 2007
    #8
  9. David Guest

    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


    <> wrote in message
    news:...
    > 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, 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
    >>
    >>
    >>
    >> commercial> wrote:
    >> > 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

    >>
    >> > <> wrote in message

    >>
    >> >news:...

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

    >
    >
    David, May 1, 2007
    #9
  10. Guest

    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" <>
    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
    >
    > <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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, 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

    >
    > >> commercial> wrote:
    > >> > 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

    >
    > >> > <> wrote in message

    >
    > >> >news:...

    >
    > >> > > 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, 2007
    #10
  11. Guest

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

    >
    > > <> wrote in message

    >
    > >news:...

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

    >
    > > >> commercial> wrote:
    > > >> > 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

    >
    > > >> > <> wrote in message

    >
    > > >> >news:...

    >
    > > >> > > 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, 2007
    #11
  12. David Guest

    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


    <> wrote in message
    news:...
    > 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, 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" <>
    >> 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

    >>
    >> > <> wrote in message

    >>
    >> >news:...

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

    >>
    >> > >> commercial> wrote:
    >> > >> > 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

    >>
    >> > >> > <> wrote in message

    >>
    >> > >> >news:...

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

    >
    >
    David, May 1, 2007
    #12
  13. Guest

    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" <>
    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
    >
    > <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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, 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" <>
    > >> 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

    >
    > >> > <> wrote in message

    >
    > >> >news:...

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

    >
    > >> > >> commercial> wrote:
    > >> > >> > 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

    >
    > >> > >> > <> wrote in message

    >
    > >> > >> >news:...

    >
    > >> > >> > > 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, 2007
    #13
  14. David Guest

    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



    <> wrote in message
    news:...
    > 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" <>
    > 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
    >>
    >> <> wrote in message
    >>
    >> news:...
    >>
    >>
    >>
    >> > 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, 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" <>
    >> >> 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

    >>
    >> >> > <> wrote in message

    >>
    >> >> >news:...

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

    >>
    >> >> > >> commercial> wrote:
    >> >> > >> > 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

    >>
    >> >> > >> > <> wrote in message

    >>
    >> >> > >> >news:...

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

    >
    >
    David, May 1, 2007
    #14
  15. Guest

    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" <>
    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
    >
    > <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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" <>
    > > 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

    >
    > >> <> wrote in message

    >
    > >>news:...

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

    >
    > >> >> > <> wrote in message

    >
    > >> >> >news:...

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

    >
    > >> >> > >> commercial> wrote:
    > >> >> > >> > 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

    >
    > >> >> > >> > <> wrote in message

    >
    > >> >> > >> >news:...

    >
    > >> >> > >> > > 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, 2007
    #15
  16. Guest

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

    >
    > > <> wrote in message

    >
    > >news:...

    >
    > > > 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" <>
    > > > 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

    >
    > > >> <> wrote in message

    >
    > > >>news:...

    >
    > > >> > 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, 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" <..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

    >
    > > >> >> > <> wrote in message

    >
    > > >> >> >news:...

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

    >
    > > >> >> > >> commercial> wrote:
    > > >> >> > >> > 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

    >
    > > >> >> > >> > <> wrote in message

    >
    > > >> >> > >> >news:...

    >
    > > >> >> > >> > > 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, 2007
    #16
  17. David Guest

    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


    <> wrote in message
    news:...
    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, 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" <>
    > 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

    >
    > > <> wrote in message

    >
    > >news:...

    >
    > > > 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" <>
    > > > 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

    >
    > > >> <> wrote in message

    >
    > > >>news:...

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

    >
    > > >> >> > <> wrote in message

    >
    > > >> >> >news:...

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

    >
    > > >> >> > >> commercial> wrote:
    > > >> >> > >> > 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

    >
    > > >> >> > >> > <> wrote in message

    >
    > > >> >> > >> >news:...

    >
    > > >> >> > >> > > 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 -
    David, May 2, 2007
    #17
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabriël
    Replies:
    0
    Views:
    452
    Gabriël
    May 27, 2004
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    863
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,763
    Smokey Grindel
    Dec 2, 2006
  4. Ron
    Replies:
    3
    Views:
    409
    Steven Cheng[MSFT]
    Oct 8, 2004
  5. Jurjen de Groot
    Replies:
    0
    Views:
    297
    Jurjen de Groot
    May 19, 2008
Loading...

Share This Page