Once the datalist is in edit mode and the text boxes and all happily appear,
how can I force the textbox to be the control with focus, so the user can
start editing without having to click the textbox first? Thanks.
Jerry 4 2747
In the past, I have put the following code in the ItemDataBound event of the
text box.
Where TextBoxToFocusId in the text box id in the datagrid
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
TextBox txt = e.Item.FindControl("TextBoxToFocusId");
RegisterClientScriptBlock("DataGridFocus",
string.Format("<script
language=\"javascript\">document.getElementById('{ 0}').focus();</script>",
txt.ClientID));
}
}
--
Jay Douglas http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.com> wrote in message
news:O6**************@TK2MSFTNGP14.phx.gbl... Once the datalist is in edit mode and the text boxes and all happily appear, how can I force the textbox to be the control with focus, so the user can start editing without having to click the textbox first? Thanks.
Jerry
Here's the problem... The Datalist control renders the code and assigns IDs
and names to all the controls. So you don't know the name of the control
that needs the focus until the html is rendered. And the name will be
different for every line in the datalist.
For instance, I named the textbox "txtName", but the ID when rendered is
something like "dlEntities__ctl4_txtName" and if I click a different record
to edit, the name would be different. How can you tell what control to set
the focus to?
Thanks.
"Jay Douglas" <ja****************@jaydouglas.com> wrote in message
news:u$**************@TK2MSFTNGP09.phx.gbl... In the past, I have put the following code in the ItemDataBound event of
the text box.
Where TextBoxToFocusId in the text box id in the datagrid
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.EditItem) { TextBox txt = e.Item.FindControl("TextBoxToFocusId"); RegisterClientScriptBlock("DataGridFocus", string.Format("<script language=\"javascript\">document.getElementById('{ 0}').focus();</script>", txt.ClientID)); } }
-- Jay Douglas http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.com> wrote in message news:O6**************@TK2MSFTNGP14.phx.gbl... Once the datalist is in edit mode and the text boxes and all happily appear, how can I force the textbox to be the control with focus, so the user
can start editing without having to click the textbox first? Thanks.
Jerry
Per the example below, you on the ItemDataBound event, you can use:
TextBox txt = (TextBox) e.Item.FindControl("txtName");
then txt.ClientID will return the full control name, ie:
dlEntities__ctl4_txtName
--
Jay Douglas http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.com> wrote in message
news:ek**************@TK2MSFTNGP09.phx.gbl... Here's the problem... The Datalist control renders the code and assigns IDs and names to all the controls. So you don't know the name of the control that needs the focus until the html is rendered. And the name will be different for every line in the datalist.
For instance, I named the textbox "txtName", but the ID when rendered is something like "dlEntities__ctl4_txtName" and if I click a different record to edit, the name would be different. How can you tell what control to set the focus to?
Thanks.
"Jay Douglas" <ja****************@jaydouglas.com> wrote in message news:u$**************@TK2MSFTNGP09.phx.gbl... In the past, I have put the following code in the ItemDataBound event of the text box.
Where TextBoxToFocusId in the text box id in the datagrid
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.EditItem) { TextBox txt = e.Item.FindControl("TextBoxToFocusId"); RegisterClientScriptBlock("DataGridFocus", string.Format("<script language=\"javascript\">document.getElementById('{ 0}').focus();</script>", txt.ClientID)); } }
-- Jay Douglas http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.com> wrote in message news:O6**************@TK2MSFTNGP14.phx.gbl... > Once the datalist is in edit mode and the text boxes and all happily > appear, > how can I force the textbox to be the control with focus, so the user can > start editing without having to click the textbox first? Thanks. > > Jerry > >
Figured it out right after I sent that note. Thanks for the info - much
appreciated.
"Jay Douglas" <ja****************@jaydouglas.com> wrote in message
news:eB**************@tk2msftngp13.phx.gbl... Per the example below, you on the ItemDataBound event, you can use:
TextBox txt = (TextBox) e.Item.FindControl("txtName");
then txt.ClientID will return the full control name, ie: dlEntities__ctl4_txtName
-- Jay Douglas http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.com> wrote in message news:ek**************@TK2MSFTNGP09.phx.gbl... Here's the problem... The Datalist control renders the code and assigns IDs and names to all the controls. So you don't know the name of the
control that needs the focus until the html is rendered. And the name will be different for every line in the datalist.
For instance, I named the textbox "txtName", but the ID when rendered is something like "dlEntities__ctl4_txtName" and if I click a different record to edit, the name would be different. How can you tell what control to set the focus to?
Thanks.
"Jay Douglas" <ja****************@jaydouglas.com> wrote in message news:u$**************@TK2MSFTNGP09.phx.gbl... In the past, I have put the following code in the ItemDataBound event
of the text box.
Where TextBoxToFocusId in the text box id in the datagrid
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.EditItem) { TextBox txt = e.Item.FindControl("TextBoxToFocusId"); RegisterClientScriptBlock("DataGridFocus", string.Format("<script
language=\"javascript\">document.getElementById('{ 0}').focus();</script>", txt.ClientID)); } }
-- Jay Douglas http://www.jaydouglas.com
"Jerry Camel" <rl*****@msn.com> wrote in message news:O6**************@TK2MSFTNGP14.phx.gbl... > Once the datalist is in edit mode and the text boxes and all happily > appear, > how can I force the textbox to be the control with focus, so the user can > start editing without having to click the textbox first? Thanks. > > Jerry > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alex |
last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk
The DataList is not as powerful as the DataGrid. It requires more work
from you since it has no default data presentation format....
|
by: bill yeager |
last post by:
I have a datagrid control within a datalist control. When
I try and do a "Find" on the control, the object comes
back with nothing and then my pgm crashes. I am 100% sure
that my datagird inside...
|
by: Davids |
last post by:
having a 100% working aspx page I wanted to create a user control from a
small DataList section (which has an ID="DataList1") of the page, so I
created an ascx file with the DataList and Register...
|
by: Olav Tollefsen |
last post by:
I have a Web Form with a DataList. Inside the ItemTemplate, I have a
DropDownList control.
<asp:DataList ID="ProductDataList" Runat="server">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1"...
|
by: yer darn tootin |
last post by:
Ahoy,
I have an aspx web page that loads an ascx control that's populated
with various items ( in a datalist ). Select an item and the page
reloads and the datalist now shows the details.
...
|
by: Hans Merkl |
last post by:
Hi,
I am trying to use a user control as EditItemTemplate in a DataList. It
loads fine but I can't figure out how to bind to the data of the DataList.
Here is what I have got so far:
...
|
by: Sam Martin |
last post by:
Hi,
I have got a User Control that contains for the sake of argument, a single
DataList control.
eg.
<asp:DataList id="DataListMain" runat="server" RepeatDirection="Horizontal"...
|
by: shantanu_kush |
last post by:
Hi there,
I am using a DataList in a composite control.
The DataList has an Custom ItemTemplate(ITemplate) which adds a Button
to the DataList Item as shown in the code below :
public class...
|
by: Victor |
last post by:
Hi. all
I have a customize web control. I have three simple properties and
customized render class. then I add this control into my datalist like
<asp:DataList ID="datalist" runat="server"...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |