c# - How to pass custom string in JavaScript function from code behind in? -


i have string structure this:

    string str = "[['<h1>heading 1</h1><p>paragraph 1</p><p>paragraph 2</p><p>paragraph 3</p>', 31, 32,1], ['<h1>heading 1</h1><p>paragraph 1</p><p>paragraph 2</p><p>paragraph 3</p>', 34, 35,2]]"; 

i trying pass string in javascript function alert not working. how can pass string in js function. far have tried not working

scriptmanager.registerstartupscript(this.page, this.page.gettype(), "test", "test('" + str + "')", true); 

js

 function test(str) {      alert(str);  } 

when check generated javascript, start test('[[' - , rest not recognised string content , gives javascript error.

you need escape string, using httputility.javascriptstringencode:

scriptmanager.registerstartupscript(this.page, this.page.gettype(), "test",  "test('" + httputility.javascriptstringencode(str) + "')", true); 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -