How to get cursor insertion point (caret position) from text box

D

DaveR

Can anybody help me to a)get the user's cursor insertion point (caret)
from a multiline textbox, using client-side script I suppose, and then
b)return the position to VB code behind?

I have tried the following client-side function suggested on this
Google Group (thank you) but I'm not sure what it's doing or how to
return the caret position to code behind ("txtReading" is the Textbox
ID):

function getcaretpos(txtReading)
{
if (txtReading.createTextRange)
txtReading.caretPos =
document.selection.createRange().duplicate();
}
 
E

Eliyahu Goldin

I don't know much about a). To solve b) you can add a hidden <input> element
in the form. It is accessible both on server and client. Set the value to
the cursor position on client and read it on server in code-behind.

Eliyahu
 
D

Dave Rudlin

Eliyahu - thanks for that - good idea - I assume this would also work
with a hidden Webcontrol Textbox? Now, does anybody know how to get the
caret position and place it in the hidden <input> element (or Textbox)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top