插入符位置 C# Web 表单
我在 C# Web 表单上更改文本框中插入符号的位置时遇到问题。我尝试了几种不同的使用 SelectionStart 设置的方法,但每次它都说...WebControls 没有 SelectionStart 的定义。有什么想法吗?
I'm having trouble changing the position of the caret in my textboxes, on a C# webform. I've tried several different ways of using the SelectionStart setting but everytime it says ...WebControls doesn't have a definition for SelectionStart. Any ideas??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信 SelectionStart 仅适用于 System.Windows.Forms。文本框。将这组属性用于 System.Web.UI .WebControls.TextBox
I believe SelectionStart is only available for System.Windows.Forms.TextBox. Use this set of properties for System.Web.UI.WebControls.TextBox
使用 Javascript 来执行此操作 - Web 控件没有 SelectionStart 属性,因为 Web 控件在服务器上执行,而不是在浏览器中执行。在服务器端设置选择没有多大意义,因为实际的交互控件仅存在于浏览器内部。
如有必要,您可以将隐藏输入字段中的提示从服务器发送到客户端,然后使用一段 Javascript 代码中的提示来更改生成的
input
字段中的选择从您的TextBox
中。Use Javascript to do this - the web control doesn't have a SelectionStart property because the web control executes on the server, not in the browser. It doesn't make much sense to set the selection on the server side, since the actual interactive control only exists inside the browser.
If necessary, you can send a hint in a hidden input field from the server to the client-side and then use that hint from a bit of Javascript code to change the selection in the
input
field that was generated from yourTextBox
.您无法在服务器端执行此操作,您必须使用客户端 JavaScript 来执行此操作,就像没有 WebForms 一样。
You can't do this on the server-side, you'd have to use client-sided JavaScript, just like without WebForms, to do this.
尝试以下代码:
这里 caret_position 是您要放置插入符的索引
Try the following code:
Here caret_position is the index at which you want to place caret