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;
}
}
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;
}
}