string locationName = "Mumbai";
Page.ClientScript.RegisterStartupScript(Type.GetType
("System.String"), "addScript", "PassValues(" + locationName + ")", true);
in javascript my code contains
<script language="javascript" type="text/javascript">
function PassValues(locationName)
{
var txtValue = locationName;
alert(txtValue);
}
</script>
Here the alert shows undefined instead of “Mumbai”
Try putting single quotes around your variable in the code behind. Without them, the browser thinks you are passing in a variable named Mumbai. What you really want to pass is the string ‘Mumbai’. You get the message, ‘undefined’, because there is no variable named Mumbai in the client side code.