tags:

views:

768

answers:

7

Hi, I need your advice with converting plain text to an URL.

The scenario will be this: The user will select some entry and then click a "convert to link" button.

The entry text the user selected will convert to (link: selected_text). I do it with JavaScript. And after that, when he clicks the Save button to save all his entry, I don't know how to store (link: selected_text) in tha database.

The URL will be like this: www.mysite.aspx?t=selected_text.

I can convert (link: selected_text) by using replace function in code-behind. But then I don't know how to show user as clickable and also by not showing <a href="www.mysite.aspx?t=selected_text">

It can be difficult to understand therefore I will show some of my codes to explain.

Private Sub Save(ByVal Entry As String) ' Entry Comes from entry textbox '

  Dim elected As String
  selected = Entry.Replace("(link: ", "<a href http://www.mysite.com?link=")
  selected = Entry.Replace(")", ">")

  ' then here starts save but not necessary to show '

End Sub
A: 

To store in database, you'll have to track the changes separately somehow and post them back to the server. I'd suggest a HiddenInput control.

Kon
A: 

I'm not sure what the problem is, could you please clarify?

Are you having problems storing it in the DB?

Robert Wagner
A: 

Thanks Fallen888,but HiddenInput is not suitable for it.By the way,i dont want to use freetextbox editor or another tool too.

Robert, No,it is easy to store database but i have problems when i want to display it.Forexample the plain text is "please click here".user selected "here",and i converted "here" word to a url.But when i want to display it,i cant show the link as hyperlink display.By the way Clearly My Problem is that i save it in database as www.mysite.com?t=here and i want to convert it to "here" while displaying.i cant do it therefore user sees it as Please click www.mysite.com?t=here

A: 

Do not save it as www.mysite.com?t=here. Just save the entry as the user types it. While showing it to user later, convert the "(link: here)" to link and show that.

Serhat Özgel
+1  A: 

If you must save processed input for some reason

(link: here)

must be converted to

(link: <a href="http://www.mysite.com?t=here"&gt;here&lt;/a&gt;)
Serhat Özgel
A: 

Save the post as the user wrote it. This will make it easier to allow editing of the post later. When you render the message you should use a regular expression to replace it with a real link. You should never replace all ")" with ">". What happends if i write "hello (world)"?

The result: Hello (world>

You can find great regular expressions here: http://regexlib.com

vimpyboy
A: 

Thanks Buyutec, ur solution works. Thanks vimpyboy, i know that i must use regular expressions but i designed this sample within 1 hour therefore no time to focus on it.