By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,844 Members | 1,859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,844 IT Pros & Developers. It's quick & easy.

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

P: n/a
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();
}
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"DaveR" <da**@bluehills.co.uk> wrote in message
news:1c**************************@posting.google.c om...
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();
}

Nov 18 '05 #2

P: n/a
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)?


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.