473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Highlighting Text and save

rakesh bairi
I am interested in saving text when user selects any text anywhere on a web page that text has to be highlighted and has to save that text as a string in C#.
when same user saw same page next time text has to be highlighted as done previously by him.
If anyone knows a simple elegant way to do this I would really appreciate it, but I'll take any solution at this point. Even if you can point me in the right directions that would be appreciated. Thanks in advance.
Sep 13 '11 #1
4 2189
Frinavale
9,735 Expert Mod 8TB
Highlighting is done client-side.

So you have to use JavaScript (a client-side scripting language) to retrieve what text is highlighted.

Then you need to somehow send that information back to the server. The best way that I've found is to use a hidden field on the page since they are accessible from both JavaScript and in your server-side code...but you could also use cookies or the query string.

You need to figure out what you need to store...and how.

Then you need to retrieve the information from the database, send it down to the browser in a way that you can access it in JavaScript so that the JavaScript code can re-highlight stuff.

If I were you I'd look for a control that's already in place that does this.

If you can't find one, then consider researching how to develop Ajax Enabled .NET Server Controls.

-Frinny
Sep 13 '11 #2
thanks for your reply i m done it
Sep 15 '11 #3
Thanks for your reply but it will not work other than IE .

I m tried with this code
Expand|Select|Wrap|Line Numbers
  1. function highlight() {
  2.   var range, sel;
  3.   // IE case
  4.   if (document.selection && document.selection.createRange) {
  5.     range = document.selection.createRange();
  6.     //range.execCommand("Bold", false, null);
  7.     range.execCommand("BackColor", "false", "yellow");
  8.     txt = document.selection.createRange().text;
  9.   } else if (window.getSelection) {
  10.     // Non-IE
  11.     sel = window.getSelection();
  12.     if (sel.rangeCount && sel.getRangeAt) {
  13.       range = sel.getRangeAt(0);
  14.       alert(range);
  15.     }
  16.     document.designMode = "on";
  17.     if (range) {
  18.       sel.removeAllRanges();
  19.       sel.addRange(range);
  20.       alert(range);
  21.     }
  22.     // document.execCommand("Bold", false, null);
  23.     document.execCommand("BackColor", "false", "yellow");
  24.     document.designMode = "ofx  f";
  25.   }
  26. }
  27. </script>
But using this code I m getting problem in FireFox but it works fine in IE,Chrome and also i have show highlight the text when same user open same page next time For that i have to store text in my database.If I m Using hidden field to assign selected HTML text then i m getting some security error .
Sep 29 '11 #4
Frinavale
9,735 Expert Mod 8TB
You should post the error you're getting so that the JavaScript experts can help you :)

-Frinny
Sep 29 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bruce Rusk | last post by:
I'm using Stephen Lebans' RTF2 control in a report, and have discovered what may be a slight bug in it. I have a lot of non-Western language (Chinese) text in my RTF field, and such records get...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
6
by: Lance Geeck | last post by:
I have a simple form where I am using a dataset called Client. On the data entry screen, there are name, address, city state and zip. I have the fields bound to the dataset field. (Properties...
2
by: jason | last post by:
hello. i am just trying to save a TextBox.Text value to a database, but strangely, when the value is changed on the web form, the changes are not recognized in the event where i try to save the...
0
by: Patty05 | last post by:
I have a datagrid on a form that update properly when form loads. When the program runs and I type in/add a new row in the datagrid, it does not save the changes. Any help would be greatly...
0
by: David | last post by:
Hello all. I am trying to implement my first server control and have run into two problems that I cannot solve. I need the assistance of someone with more experience. My goal was to create an...
2
by: toddw607 | last post by:
Hi all! I am attempting to bring an SQL Server table into ASP.NET using the datagrid . I have set all cells to be a text box by which the user can just click on and edit the cell. I have a...
9
by: Steven Bethard | last post by:
I have some text and a list of Element objects and their offsets, e.g.:: ... (etree.Element('a'), 0, 21), ... (etree.Element('b'), 11, 18), ... (etree.Element('c'), 18, 18), ... ] ...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.