简体   繁体   English

如何在ASP.NET的WebControl文本框中设置光标位置?

[英]How can I set the cursor position in a WebControl textbox in ASP.NET?

I need to set the cursor to the end of a webcontrol textbox. 我需要将光标设置在WebControl文本框的末尾。 How can I do that? 我怎样才能做到这一点?

You can do that only with JavaScript.on page load event. 您只能使用JavaScript.on页面加载事件来做到这一点。 Just add this code into your section by provideing id of your textbox 只要提供您的文本框ID,即可将此代码添加到您的部分中

<script type="text/javascript">
window.onload = function() {
    var oInput = document.getElementById("<%=TextBox1.ClientID%>");
    oInput.focus();    
    oInput.value += "";
};
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在ASP.NET中创建具有与表单的输入元素绑定的公共属性的WebControl? - How can I create a WebControl in ASP.NET that has public properties tied to the input elements of a form? 可点击的Webcontrol,ASP.NET - Clickable Webcontrol, ASP.NET 如何使用 currentDate 变量在 asp.net 文本框控件中设置到达日期? - How can I use my currentDate variable to set the arrival date in the asp.net textbox control? 如何通过标记在ASP.NET WebControl上设置自定义对象属性 - How to set custom object property on ASP.NET WebControl through markup 如何将光标放在 ASP.NET 文本框的开头以获得焦点? - How to place the cursor at the start of ASP.NET textbox on getting the focus? 如何在 asp.net 网站中实现 SOTag 文本框? - How can I implement SOTag textbox in asp.net website? 如何在asp.net中自动调整文本框的高度? - How can I autosize textbox height in asp.net? Asp.net图表,如何将X轴标签位置设置为左对齐而不是居中? - Asp.net chart, how can I set the X axis label position to left aligned instead of centered? ASP.Net-如何从另一个WebControl中添加一个HiddenField并对其进行维护? - ASP.Net - How do I add a HiddenField from another WebControl and maintain it? 查找文本框光标位置,行号。 和列号 在asp.net - finding Textbox cursor position,line no. and column no. in asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM