简体   繁体   English

使用后面代码中的参数调用 javascript function

[英]call javascript function with parameter from code behind

hii, i have to call a function to display a google map.嗨,我必须调用 function 来显示谷歌 map。 the code is in.aspx page and i have to call the function from the corresponding.aspx.cs page.代码是 in.aspx 页面,我必须从对应的.aspx.cs 页面调用 function。 my problem is that when i call the function without any parameter it works fine and the map is displayed.我的问题是,当我在没有任何参数的情况下调用 function 时,它工作正常并显示 map。 however as soon as i try to send a string as argument the map doesnt get displayed.但是,一旦我尝试发送一个字符串作为参数,map 就不会显示。 !! !!

Page.ClientScript.RegisterStartupScript(Type.GetType("System.String"), "addScript", "initialize()", true);

when i use this statement the map gets displayed.当我使用此语句时,将显示 map。 but when i write但是当我写

Page.ClientScript.RegisterStartupScript(Type.GetType("System.String"), "addScript", "initialize('" + finaladd + "','" + name_and_add + "')", true);

its not worknig.. finaladd and name_and_add are two strings.它不起作用.. finaladd 和 name_and_add 是两个字符串。 they are however quite long ones.然而,它们很长。

Make sure that both finaladd and name_and_add are properly escaped.确保finaladdname_and_add都正确转义。 In this case you need to make sure that the strings don't contain any single quote ' character.在这种情况下,您需要确保字符串不包含任何单引号'字符。

The easiest way to accomplish this is a simple .Replace("'", @"\'") on both variables.完成此操作的最简单方法是对两个变量都使用简单的.Replace("'", @"\'")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM