How do i do javascript with ASP.NET?

G

Guest

i have an ASP.NET application that displays confirmation prompts using
javascript. The text of these messages comes from a string resource file. The
script is attached to the button. Code is similar to this:

btn_resetPassword.Attributes.Add("OnClick",
"javascript:return dConfirm('" + confirmationMessage + "')");

This works great unless the message contains an apostrophe. User a word like
"user's" and the routine never runs. No error (other than a browser
notification of "unexpected )"), just doesn't run

We have tried used \, html encoding, double quotes and doubling up the
apostrophe. None of it works. Using the \ does work if we take it out of C#
and put it in a separate javascript file but if we do that we no longer have
access to our string resource file so that's not going to fly

There's got to be a way to do this (i'm an eternal optimist) but we're run
out of ideas as to how
 
G

Guest

Replace apostrophe with \\' like below..it will work fine..
confirmationMessage.Replace("'","\\'")
 
G

Guest

i love the Internet. So many smart people

Yup, that did it. In retrospect, i feel dumb for not thinking of this. Thanks!

-baylor
 
Joined
Apr 22, 2014
Messages
1
Reaction score
0
Hi,

Is there a common way to check all apostrophes in resource file?Like in code-behind or using java script?

I have multiple resource files and multiple keys for localization support in .Net for SharePoint pages.

I want to check them before using in my popup and replace the text with escape sequence.
Please help me here to find best solution
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top