1

I am working on web page in which I have to save typed content in textarea after 10 sec of last key press, once data is saved I am using Focus() to focus again in text area because it is focusing out.

txtClientArea.Focus();

Problem is that it always focus in start of text area so each time I need to either click in the end of content of press End key. I am not using .cs file as a back end but writing code is script tag.

<script type="text/C#" language="c#" runat="server">

//.........

</script>

is there any way to focus at the end using code. I have tried using js in code but closing tag of script conflict with c# script tag.

1 Answers1

1

Replace below line with txtClientArea.Focus(); in your code, it works for me.

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "Show Windows" + new Random().Next().ToString(), "var lsArea = document.getElementById('" + txtClientArea.ClientID + "'); lsArea.focus();var val = lsArea.value; lsArea.value = ''; lsArea.value=val;", true);
Keval Gangani
  • 1,326
  • 2
  • 14
  • 28