Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox Highlighting Text and Replacing

Status
Not open for further replies.

gi11ies

Programmer
Mar 26, 2002
52
Im trying to make a very basic text editor, that has image buttons for formatting the text. Just now I have if so if you want bold text ... you press the relevant image button and [[]b] goes into the textbox and when you finish the bold text you click it again [[]/b] goes into the text box.

I use this code.

Code:
Sub btnBold_Click (Sender as Object, e as ImageClickEventArgs)
	If Session("boldText") = "boldOff" then
		Dim textForBold As String = txtContent.text
		Dim textBoldStart As String = textForBold + "[[]b]"
		txtContent.text = textBoldStart
		lblStatus.Text = "Text Entry is Bold. (click on Bold Text button again to end Bold Text)"
		Session("boldText") = "boldOn"
	Else
		Dim textForBold As String = txtContent.text
		Dim textBoldEnd As String = textForBold + "[[]/b]"
		txtContent.text = textBoldEnd
		lblStatus.Text = "Text Entry is Normal."
		Session("boldText") = "boldOff"		
	End If
End Sub

I do replaces when the page is opened, ie [&#91;]b] is <b> and [&#91;]/b] is </b>.

What I want to do is use the cursor to highlight text in the textbox and press the bold image button and it will automatically make that text bold, by doing a replace in the textbox of the selected text putting in [&#91;]b] and [&#91;]/b]

for example

In the textbox

The dog ran after the ball.

If I selected 'dog ran after' so its highlighted, and then pressed the bold image button I created, it replaces the text to.

The [&#91;]b]dog ran after[&#91;]/b] the ball.

Does anyone have any tips on how to do this?

Gillies

 
You'll have to use javascript to do that. Try asking in the javascript forum (forum216)


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Gillies - After you post this over at Javascript do a general search on this - I have seen several times sites that have this type of javascript code ready to go.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top