How do i do javascript with ASP.NET?

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Replace apostrophe with \\' like below..it will work fine..
confirmationMessage.Replace("'","\\'")
 
i love the Internet. So many smart people

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

-baylor
 
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:
Back
Top