• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

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
0
ipgbarry
Asked:
ipgbarry
1 Solution
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now