Set focus on usercontrol datagrid textbox
-
Hi Guys I have datagrid on usercontrol. Usercontrol i droped on web page. On edit command button click event how can i set focus on my edit text box. Any help appriciated.
First solution which comes to my mind is via javascript. Create a hidden variable in your page. You can do so with plain html in aspx page or with the help of ASP.NET javascript help functions.
this.Page.RegisterHiddenField("myFocusField","myhiddenfield");
this code results in a html below. Now change your code as this.this.Page.RegisterHiddenField("myFocusField",FindName());
private string FindName()
FindName function will return unique name of your edit controls. You can take it withthis.UniqueID;
code piece in your edit control. After that write a startupscript in your aspx page.var vFocText = document.myFocusField.value; var vFoc = document.getElementById("vFocText"); vFoc.focus()
Education is no substitute for intelligence. That elusive quality is defined only in part by puzzle-solving ability. It is in the creation of new puzzles reflecting what your senses report that you round out the definition. Frank Herbert -
First solution which comes to my mind is via javascript. Create a hidden variable in your page. You can do so with plain html in aspx page or with the help of ASP.NET javascript help functions.
this.Page.RegisterHiddenField("myFocusField","myhiddenfield");
this code results in a html below. Now change your code as this.this.Page.RegisterHiddenField("myFocusField",FindName());
private string FindName()
FindName function will return unique name of your edit controls. You can take it withthis.UniqueID;
code piece in your edit control. After that write a startupscript in your aspx page.var vFocText = document.myFocusField.value; var vFoc = document.getElementById("vFocText"); vFoc.focus()
Education is no substitute for intelligence. That elusive quality is defined only in part by puzzle-solving ability. It is in the creation of new puzzles reflecting what your senses report that you round out the definition. Frank HerbertAcually i solved this issue. Any way Thanks a lots for your solution. Here is my solution: On Edit Command public void Edit(object sender,DataGridCommandEventArgs e) { dgNotes.EditItemIndex = e.Item.ItemIndex; BindNoteData(); des.Visible = false; TextBox _txt; _txt = (TextBox) MyDatagridName.Items[e.Item.ItemIndex].Cells[3].FindControl("txtDescreption"); Page.RegisterStartupScript("focus","" + "frm." + _txt.ClientID + ".focus();" + "frm." + _txt.ClientID + ".select();" + "<" + "/script>"); } Note: frm = Form name where i droped usercontrol. Once again thanks lot Atilla Ozgur for your solution. </x-turndown>