从后面的代码创建javascript数组 [英] create javascript array from code behind

查看:78
本文介绍了从后面的代码创建javascript数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码不见了

i have my code behind

SiteServices siteServiceobj = new SiteServices();
            List<Site> siteList = siteServiceobj.GetAllSites(2);
            List<string> latLongList = (from site in siteList select "'" + site.NominalLat.ToString() + "," + site.NominalLong.ToString() + "'").ToList<string>();
            var geocodevalues = string.Join(",", latLongList.ToArray());
            List<string> OmessageList = (from site in siteList select "'<span class=formatText >" + site.SiteName + "!!!</span>'").ToList<string>();
            String message = string.Join(",", OmessageList.ToArray());

            ClientScript.RegisterArrayDeclaration("locationList", geocodevalues);

            ClientScript.RegisterArrayDeclaration("message", message);


并从前端开始
我正在使用以下脚本


and from front end
i am using following script

<script type="text/javascript">
       function alertfunction() {

           alert(locationList);
           alert(message);


       }
       window.onload = alertfunction;
    </script>




但它显示loca




but it is showing loca

tionList

是未定义的
有人可以在这里帮我吗?

is undefined
can anyone help me out here

推荐答案

在触发onload事件之前,变量可能无法完全下载.

尝试将RegisterStartupScript与alertFunction而不是window.onload
The variables may not be completely downloaded before the onload event is fired.

Try using RegisterStartupScript with the alertFunction rather than window.onload


这篇关于从后面的代码创建javascript数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆