This is a migrated thread and some comments may be shown as answers.

Focus on a control on RadGrid row click is lost on Page_Load due to ActiveRow script in IE

1 Answer 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erik Brown
Top achievements
Rank 1
Erik Brown asked on 11 Sep 2008, 09:31 PM
Hi,

On Row Seleted or Edit, I'm displaying info in a TextArea and dynamically setting focus to the TextArea. Below is the code.

The functionality works fine in Firefox. However, in IE, I get Focus on the TextArea and then loose it as I found out, that the RadGrid's script of displaying the ActiveRow is executed after my script is executed. Please advice as to how can I resolve this. I have Keyboard Support enabled.

public static void SetFocus(Control control)
        {
            StringBuilder sb = new StringBuilder();
 
            sb.Append("\r\n<script language='JavaScript'>\r\n");
            sb.Append("<!--\r\n");
            sb.Append("window.onload = function ()\r\n");
            sb.Append("{\r\n");
            sb.Append("\tdocument.getElementById('");
             sb.Append(control.ClientID);
            sb.Append("').focus();\r\n");
            sb.Append("\tdocument.getElementById('");
 
            sb.Append(control.ClientID);
            sb.Append("').scrollIntoView(true);\r\n");
            sb.Append("alert('Got Focus');");
            //sb.Append("'].focus();\r\n");
            sb.Append("};\r\n");
            //sb.Append("window.onload = SetFocus;\r\n");
            sb.Append("// -->\r\n");
            sb.Append("</script>");
 
            control.Page.RegisterStartupScript("SetFocus", sb.ToString());
           
        }
 
        protected void RadGrid2_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)
        {
            if ((e.CommandName == "RowClick" || e.CommandName == "Edit") && e.Item is GridDataItem)
            {
                textBoxData.Text = "Row clicked " + e.Item.RowIndex.ToString();
                SetFocus(textBoxData);
            }
           
            if (e.CommandName == "Edit" && e.Item is GridDataItem)
            {
                e.Item.Edit = false;
               
            }
        }

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 15 Sep 2008, 11:08 AM
Hi Erik Brown,

You may try calling the function after some timeout. Also I suggest to use MS AJAX framework's pageLoad client method instead using the window's onload event directly. I have attached a simple page which demonstrates this approach.

Please give it a try and let us know if this helps.

Regards,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Erik Brown
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or