[SOLVED] TextBox SelectionLength and SelectionStart attributes always 0

Answered
0
0

Hello! I created a class inherited from the TextBox class. In the OnKeyPress method I try to get the selected text, but the SelectionLength and SelectionStart attributes are always 0.

private void OnKeyPress(object sender, KeyPressEventArgs e)
{

var index = this.SelectionStart;
var length = this.SelectionLength;

}

Сan you please tell me i am doing something wrong.

  • You must to post comments
Best Answer
0
0

Keyboard events processed on the server have already occurred on the client browser: all server events are by definition asynchronous. The SelectionStart/Length/Text return the selection in the textbox, while you type there is nothing selected. You can use client side events if you want to handle the keyboard synchronously you can attach javascript events:

https://wisej.com/support/question/textbox-keypresseventhandler-e-handled-true-doesnt-work

On the client side you can use:

this.getTextSelectionStart();
this.getTextSelectionEnd();
this.getTextSelectionLength();
this.getTextSelection();
this.setTextSelection(start, end);
this.clearTextSelection();
this.selectAllText();

 

 

 

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.