Server.URLEncode
<%= Server.URLEncode(text) %>
Use this method any time you are writing database fields or form values, to ensure that any special characters ( like ? # etc. ) are URL-escaped.