0

I am calling javascript function through:

    <a href='javascript:void(0)' onclick='javascript:onEditRevPrepare("<%# 
Convert.ToString(Eval("ReviewTitle")))%>")'>

When single quot (') is present in Eval("ReviewTitle") its not calling the function.

I tried with:

Convert.ToString(Eval("ReviewTitle"))).Replace("'","\")

But this does not worked.

Also tried with:

 <a href='javascript:void(0)' onclick='javascript:onEditRevPrepare("&quot;<%# 
    Convert.ToString(Eval("ReviewTitle")))%>&quot;")'>

But this also not worked.

EDIT

As and when i add ' or / in replace i stops getting line of javascript , which indicates function calling is not correct:

enter image description here

Please look at the broken line after replace

C Sharper
  • 8,284
  • 26
  • 88
  • 151

1 Answers1

1

At it's simplest, you could

//Convert.ToString(Eval("ReviewTitle"))).Replace("'","\") //broken
  Convert.ToString(Eval("ReviewTitle"))).Replace("'","\\'").Replace("\"","\\\"")

However, you really should look at javascript encoding for a more robust solution.

Community
  • 1
  • 1
spender
  • 117,338
  • 33
  • 229
  • 351