0

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.

5
  • Could you show finaladd and name_and_add sample values? Commented Jun 6, 2011 at 10:07
  • its a string of name and address of employees and they are seperated by '~' . in the javascript function the string is split using .split method. Commented Jun 6, 2011 at 10:19
  • 1
    You'll have to debug it. Ignore how you generate the Javascript for now, and see if the Javascript itself is OK. Do the values look correct, and very important in Javascript, a single line? Use "\n" (backslash n, not a newline) if you need a newline. Commented Jun 6, 2011 at 21:35
  • And, most importantly: does it work with manually entered Javascript? Commented Jun 6, 2011 at 21:41
  • hey bart,y is it that i need to escape backslashes.??? Commented Jun 7, 2011 at 3:47

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Backslashes need to be escaped, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.