473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can't edit dynamically created textbox

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.
Nov 19 '05 #1
2 1859
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.

Nov 19 '05 #2
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" <mw*****@discussions.microsoft.com> wrote in message
news:D0**********************************@microsof t.com...
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.

Nov 19 '05 #3

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

Similar topics

6
by: Bhavin | last post by:
Anybody quickly replies it, would be a great help! I try to create dynamic array of textboxes control in ASP.NET(C#). I got the following error while I tried to assign value to ID property of...
0
by: Mike | last post by:
Hi, I am having problems with my program, the problem is it will not put the datagrid into edit mode. The .aspx page has the following code in it : - <asp:datagrid id="DataGrid2"...
0
by: doronb | last post by:
hello my question is : i define dynamic columns to datagrid , 4 columns are databound and 1 columne is "edit template column" and only this col editable , i define function for update when...
1
by: dx | last post by:
I'm extremely frustrated with ASP.NET...again! To me this should be as simple as setting oCheckBox.Checked = True.. yet for some reason it isn't. I have a user control (ascx) that that has a...
1
by: Kum | last post by:
Hi, I need help in asp.net dynamic textbox controls validation. I am creating textbox controls dynamically on a asp.net webpage. Now after creating the textboxes on the page I want to validate...
7
by: mef526 | last post by:
I would like to reference a dynamically created control and I know the name. I would like to use the following: Dim strName as String = "txtControl1" ' This is the ".Name" used when textbox was...
2
by: BillE | last post by:
I need to create a multi-line label dynamically. Since labels aren't multi-line, I'm creating a textbox and making it look like a label with the multiline property set to true. I want to...
2
by: Radu | last post by:
Hi. I have a page with the following html: __________________________________________________________ <h1>Dynamic Controls Test</h1> <hr /> <asp:TextBox ID="txtProduct1" Text="txtProduct 1"...
3
by: raghulvarma | last post by:
I have created only one object for the textbox and that particular textbox is being repeated as many times I want.But if I want to add the values in the database from each and every textbox which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.