Can't edit dynamically created textbox

Discussion in 'ASP .Net' started by =?Utf-8?B?bXdoYWxlbg==?=, Jan 28, 2005.

  1. Hi All,

    I've dynmaically created a textbox, but I can't edit it. When I click on
    it, the cursor flashes for a second, but then goes away and I can't enter any
    text or do anything with the value in the box.

    Here's the code I've used to create the control. It's within a datagrid
    that is bound to a dataTable so the action happens in the ItemDataBound event.

    Private Sub dgItems_ItemDataBound(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgItems.ItemDataBound
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
    ListItemType.AlternatingItem Then
    Dim dtItems As New DataTable
    dtItems = CType(Session("ItemsDT"), DataTable)

    'this is what I can't edit
    Dim txtQty As New TextBox
    Page.Controls.Add(txtQty)
    e.Item.Cells(0).Controls.Add(txtQty)
    txtQty.ID = "txtQty" & e.Item.ItemIndex
    txtQty.EnableViewState = True
    txtQty.Text = dtItems.Rows(e.Item.DataSetIndex)(0)
    txtQty.Width = WebControls.Unit.Pixel(30)

    Dim lblDesc As New Label
    lblDesc.EnableViewState = True
    lblDesc.Text = dtItems.Rows(e.Item.DataSetIndex)(1)
    e.Item.Cells(1).Controls.Add(lblDesc)

    Dim lblUnitPrice As New Label
    lblUnitPrice.EnableViewState = True
    lblUnitPrice.Text = dtItems.Rows(e.Item.DataSetIndex)(2)
    e.Item.Cells(2).Controls.Add(lblUnitPrice)

    End If
    End Sub

    Thanks.
     
    =?Utf-8?B?bXdoYWxlbg==?=, Jan 28, 2005
    #1
    1. Advertising

  2. I figured out what was causing it. In the body tag of the page it had
    onblur="self.focus();".

    So, now I can edit the textbox, but as per my directive from above, the page
    is a popup window and needs to stay on top and that's the code that was doing
    that.

    Can anyone think of any alternative ways of making that happen?


    "mwhalen" wrote:

    > Hi All,
    >
    > I've dynmaically created a textbox, but I can't edit it. When I click on
    > it, the cursor flashes for a second, but then goes away and I can't enter any
    > text or do anything with the value in the box.
    >
    > Here's the code I've used to create the control. It's within a datagrid
    > that is bound to a dataTable so the action happens in the ItemDataBound event.
    >
    > Private Sub dgItems_ItemDataBound(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgItems.ItemDataBound
    > If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
    > ListItemType.AlternatingItem Then
    > Dim dtItems As New DataTable
    > dtItems = CType(Session("ItemsDT"), DataTable)
    >
    > 'this is what I can't edit
    > Dim txtQty As New TextBox
    > Page.Controls.Add(txtQty)
    > e.Item.Cells(0).Controls.Add(txtQty)
    > txtQty.ID = "txtQty" & e.Item.ItemIndex
    > txtQty.EnableViewState = True
    > txtQty.Text = dtItems.Rows(e.Item.DataSetIndex)(0)
    > txtQty.Width = WebControls.Unit.Pixel(30)
    >
    > Dim lblDesc As New Label
    > lblDesc.EnableViewState = True
    > lblDesc.Text = dtItems.Rows(e.Item.DataSetIndex)(1)
    > e.Item.Cells(1).Controls.Add(lblDesc)
    >
    > Dim lblUnitPrice As New Label
    > lblUnitPrice.EnableViewState = True
    > lblUnitPrice.Text = dtItems.Rows(e.Item.DataSetIndex)(2)
    > e.Item.Cells(2).Controls.Add(lblUnitPrice)
    >
    > End If
    > End Sub
    >
    > Thanks.
     
    =?Utf-8?B?bXdoYWxlbg==?=, Jan 28, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?bXdoYWxlbg==?=

    MWells Guest

    I believe there is a way in javascript to open a new window as a modal
    dialog, meaning that you can't push it behind the parent window or interact
    with the parent window until the dialog is closed.

    "mwhalen" <> wrote in message
    news:D...
    > I figured out what was causing it. In the body tag of the page it had
    > onblur="self.focus();".
    >
    > So, now I can edit the textbox, but as per my directive from above, the

    page
    > is a popup window and needs to stay on top and that's the code that was

    doing
    > that.
    >
    > Can anyone think of any alternative ways of making that happen?
    >
    >
    > "mwhalen" wrote:
    >
    > > Hi All,
    > >
    > > I've dynmaically created a textbox, but I can't edit it. When I click

    on
    > > it, the cursor flashes for a second, but then goes away and I can't

    enter any
    > > text or do anything with the value in the box.
    > >
    > > Here's the code I've used to create the control. It's within a datagrid
    > > that is bound to a dataTable so the action happens in the ItemDataBound

    event.
    > >
    > > Private Sub dgItems_ItemDataBound(ByVal sender As Object, ByVal e As
    > > System.Web.UI.WebControls.DataGridItemEventArgs) Handles

    dgItems.ItemDataBound
    > > If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
    > > ListItemType.AlternatingItem Then
    > > Dim dtItems As New DataTable
    > > dtItems = CType(Session("ItemsDT"), DataTable)
    > >
    > > 'this is what I can't edit
    > > Dim txtQty As New TextBox
    > > Page.Controls.Add(txtQty)
    > > e.Item.Cells(0).Controls.Add(txtQty)
    > > txtQty.ID = "txtQty" & e.Item.ItemIndex
    > > txtQty.EnableViewState = True
    > > txtQty.Text = dtItems.Rows(e.Item.DataSetIndex)(0)
    > > txtQty.Width = WebControls.Unit.Pixel(30)
    > >
    > > Dim lblDesc As New Label
    > > lblDesc.EnableViewState = True
    > > lblDesc.Text = dtItems.Rows(e.Item.DataSetIndex)(1)
    > > e.Item.Cells(1).Controls.Add(lblDesc)
    > >
    > > Dim lblUnitPrice As New Label
    > > lblUnitPrice.EnableViewState = True
    > > lblUnitPrice.Text = dtItems.Rows(e.Item.DataSetIndex)(2)
    > > e.Item.Cells(2).Controls.Add(lblUnitPrice)
    > >
    > > End If
    > > End Sub
    > >
    > > Thanks.
     
    MWells, Jan 29, 2005
    #3
    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. Jack Johnston
    Replies:
    5
    Views:
    562
    Natty Gur
    Jul 28, 2003
  2. Mike
    Replies:
    0
    Views:
    393
  3. msimmons
    Replies:
    0
    Views:
    490
    msimmons
    Jul 16, 2009
  4. Sharon McCarty
    Replies:
    0
    Views:
    252
    Sharon McCarty
    Nov 24, 2004
  5. Mike
    Replies:
    0
    Views:
    138
Loading...

Share This Page