Search for the cursor position in the text field, line number. and column number. in asp.net

I am starting to develop web applications. I have a windows application code. I have to convert such functionality to a web application. I have a control text box. I am loading text in this text box. I want to find the current cursor position, row number and column number. The code for the Windows application is shown below:

private void Form1_Load(object sender, EventArgs e) { textBox1.Text = @"This is a demo for text box control I am trying to find the cursor position , line no and column no of the cursor."; } private void textBox1_Click(object sender, EventArgs e) { textBox1.SelectionStart++; label2.Text = textBox1.SelectionStart.ToString(); int i = textBox1.GetLineFromCharIndex(textBox1.SelectionStart); label3.Text = i.ToString(); int j =textBox1.SelectionStart - textBox1. GetFirstCharIndexFromLine(i); label4.Text = j.ToString(); } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Right) || (e.KeyCode == Keys.Left) || (e.KeyCode == Keys.Down)) { textBox1.SelectionStart++; label2.Text = textBox1.SelectionStart.ToString(); int i = textBox1.GetLineFromCharIndex(textBox1.SelectionStart); label3.Text = i.ToString(); int j = textBox1.SelectionStart - textBox1.GetFirstCharIndexFromLine(i); label4.Text = j.ToString(); } } 
+4
source share
1 answer

as the accepted answer in this post, you need to use javascript to get the SelectionStart and SelectionEnd in your side of the clinic. then publish the result (may use a hidden input value) on the server with data reset:

How to get selected text from textbox control using javascript

+2
source

Source: https://habr.com/ru/post/1391384/


All Articles