call javascript function with parameter from code behind
hii, i have to call a function to display a google map. the code is in .aspx page and i have to call the function from the corresponding .aspx.cs page. my problem is that when i call the function without any parameter it works fine and the map is displayed. however as soon as i try to send a string as argument the map doesnt get displayed. !!
Page.ClientScript.RegisterStartupScript(Type.GetType("System.开发者_开发问答String"), "addScript", "initialize()", true);
when i use this statement the map gets displayed. 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. they are however quite long ones.
Make sure that both finaladd
and name_and_add
are properly escaped. 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.
精彩评论