asp.net - How to get position of cursor in a textbox VB.NET Web Form -


i have textbox , want know position of cursor (preferably character index in textbox.text) when button clicked , want in server side using vb.

<asp:textbox id="txtboxexplanation" runat="server" height="530px" textmode="multiline" width="500px" maxlength="600"></asp:textbox> 

thanks!

here how can achieve looking for. when textarea (multi line textbox) loses focus (onblur), try caret position , place hidden field, have access on server.

on page, need include javascript - getcaret function taken [here][1]

<script type="text/javascript">  function savecaretpos(txt) {   document.getelementbyid('<% =caretpos.clientid %>').value = getcaret(txt);  } function getcaret(el) {    if (el.selectionstart) {      return el.selectionstart;    } else if (document.selection) {      el.focus();       var r = document.selection.createrange();      if (r == null) {        return 0;      }       var re = el.createtextrange(),          rc = re.duplicate();      re.movetobookmark(r.getbookmark());      rc.setendpoint('endtostart', re);       return rc.text.length;    }     return 0;  }  </script> 

then add hidden input field inside of form, can send caret position server.

 <asp:hiddenfield runat="server" id="caretpos" /> 

then adjust multiline textbox this:

<asp:textbox id="txtboxexplanation" runat="server" height="530px" textmode="multiline" width="500px" maxlength="600" onblur="savecaretpos(this);"></asp:textbox> 

now, when post server, can access caret position, this

dim mycaretpos integer = caretpos.value        ' mycaretpos contains position caret in when form submitted. 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -