A: 

maybe you need to escape quotes? replace every single quote with a backslashed single quote.

can you paste the exact browser error message with the javascript/html source lines where the error is happening.

aularon
I've checked escape quotes. Problem seems to be as I stated above with Line Feed and Carrige Return.Here is the output from Debug Toolbar:Line: 27Character: 1497Code: 0Error Message: Unterminated string constant
Benxy
A: 

It's unlikely to be a problem with the error message and HtmlEncode(), and more likely some other javascript running on your page that's causing the issue.

Provide the error message here and we can tell for sure.

Also, is this public-facing? You really shouldn't be displaying internal errors to the user, especially not when it comes from the database, you could be opening up a security hole.

Amethi
Benxy
Yes, I am aware of showing error message to user, but at the moment this is desirable. No matter how strange it sounds.. :)
Benxy
Noooo, internal messages should never be presented to the user! :) Write them out to a log file or something. Elmah, Log4Net are good for this. Just supply a "An error has occured, please contact support" message when an exception is caught...You could spend a lot of time trying to fix a problem here that you really don't need to.But to answer your question, a regular expression to strip all but alpha-numeric characters and some punctuation would work.
Amethi
Showing internal messages to user is not an issue here as I stated before. I am aware what user should see and what shouldn't see.Regex you say, could try that... Thanks for your help..
Benxy