C# how to insert this javascript into SQL onFocus="alert('Error');"

HI am writing a C# app

I want to add some javascript into my SQL server.
Eg
onFocus="alert('Error');"
it errors on the single quotes. If I type 2 single quotes in my texBox;
Eg
onFocus="alert(''Error'');"
it works fine. I am trying to handle this in my code save doing it in the textbox.
I have paramatised the string in the data class I have made which I thought would sort it out it that didn't.
I guessing I need to use .Replace but have not managed to get the syntax right.

Any help would be appreciated.

Cheers

Baz
ipgbarryAsked:
Who is Participating?
 
philipjonathanCommented:
Is this what you mean?
onFocus = textbox.Text.Replace("'", "''");
The first argument is single '
The second argument is double '
0
 
ipgbarryAuthor Commented:
Great thanks worked first time.
string js = textbox.Text.Replace("'", "''");
 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.