Convert plain text to Clickable link or PlainText link in asp.net

I need your advice on converting plain text to URL.

The script will be like this: the user selects a post, and then the "convert to link" button.

The input text that the user selected is converted to (link: selected_text)

. I am doing this with JavaScript. And after that, when he clicks the Save button to save his entire record, I don't know how to store (link: selected_text)

in that database.

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

.

I can convert (link: selected_text)

using the encoded replace function. But then I don't know how to show the user as interactive and also not show<a href="www.mysite.aspx?t=selected_text">

This can be difficult to understand, so I'll 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

      

0


source to share


4 answers


If you must save processed input for any reason

(link: here)

      



needs to be converted to

(link: <a href="http://www.mysite.com?t=here">here</a>)

      

+1


source


To save to the database, you have to somehow track the changes separately and push them back to the server. I would suggest the HiddenInput control.



0


source


Don't save it as www.mysite.com?t=here. Just save the entry as the user enters it. When showing it to the user later, transform "(link: here)" to link and show it.

0


source


Save the message when the user wrote it. This will make it easier to edit the post later. When you post, you must use a regular expression to replace it with a real link. You should never replace all ")" with ">". What happens if I write "hello (world)"?

Result: Hello (world>

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

0


source







All Articles