c# - 使用 C# 在 asp.net 网页的最后一个字符中将焦点设置在文本框中

标签 c# asp.net textbox focus

我在 asp.net 网页中有一个文本框。在回发的情况下,我需要将焦点设置在此文本框中的最后一个字符上。我如何在不使用 jQueries 之类的情况下使用 c# 执行此操作。 谢谢

最佳答案

这是 Use JavaScript to place cursor at end of text in text input element 中提出的解决方案的变体。 :

void btnPostBack_Click(object sender, EventArgs e)
{
    txtFocus.Attributes["onfocus"] = "var value = this.value; this.value = ''; this.value = value; onfocus = null;";
    txtFocus.Focus();
}

关于c# - 使用 C# 在 asp.net 网页的最后一个字符中将焦点设置在文本框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36793112/

相关文章:

c# - 如何在 C# 中创建完全参数化的方法委托(delegate)?

c# - 如何使用 C# 和 SQL Server 连接到数据库

asp.net - 多行 TextBox 多个换行符

html - 如何在手机上隐藏页脚

c# - ASP.NET 图表控件,是否可以在饼图上使用渐变?

c# - 在 Asp.net Core 中提交 ajax 表单后的 RedirectToAction

c# - 重新保存Blazor WASM的.razor文件

c# - 对 ASP.net 服务器控件进行分组以修改属性,而无需按名称引用它们

javascript - 当用户点击 html 按钮时避免回发

c# - KeyEventArgs.Key 到 char