<asp:TextBox ID="txtValore" runat="server" onfocus='setTextBoxFocused(this.id);SetEndCursor(this)'
AutoPostBack="true" OnTextChanged="txtValore_TextChanged"></asp:TextBox>
function setTextBoxFocused(clientId)
{
$.get("SetFocused.aspx?clientId=" + clientId + "&ts=" + new Date().getTime());
}
function SetEndCursor(textBox)
{
if (textBox.createTextRange)
{
var fieldRange = textBox.createTextRange();
fieldRange.moveStart('character', textBox.value.length);
fieldRange.select();
}
}
CodeBehind nel controllo con UpdatePanel:
if (Session["TextBoxFocused"] != null)
{
ScriptManager.GetCurrent(this.Page).SetFocus(Convert.ToString(Session["TextBoxFocused"]));
}
La pagina richiamata da JSON: SetFocused.aspx
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (Page.IsPostBack)
return;
Session["TextBoxFocused"] = Request.QueryString["clientId"];
}
Grazie a Gae.
Technorati tags:
.NET,
Csharp