在asp.net的背后code创建JavaScript变量 [英] Create javaScript variable in code behind of asp.net

查看:105
本文介绍了在asp.net的背后code创建JavaScript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何注册在服务器端(后端)和访问它的客户端(JavaScript文件)JavaScript变量,没有一个隐藏字段,文字等。

How do I register a Javascript variable on the server side (backend) and access it on the client side (Javascript file), without a hidden field, Literal, etc.?

推荐答案

您可以使用的RegisterClientScriptBlock 从页面的ClientScriptManager - 功能。

You can use the RegisterClientScriptBlock-Function from the Page's ClientScriptManager.

Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "initMyClientVariable", "var myClientVariable=null;", True)

修改:根据新的信息,您要注册一个客户端数组,使用ClientScriptManager的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerarraydeclaration.aspx\">RegisterArrayDeclaration方法。

EDIT: according to your new informations, that you want to register a client array, use ClientScriptManager's RegisterArrayDeclaration Method.

VB.Net例如:

Dim myArrayValue As String = """1"", ""2"", ""text"""
Page.ClientScript.RegisterArrayDeclaration("myClientArray", myArrayValue)

据我的意见,你需要从外部的js文件访问该变量的新的信息:你应该在JS数组作为参数传递给函数在JS文件。例如:

According to the new information in my comments that you need access to that variable from an external js-file: you should pass the js-array as argument to the function in the js-file. For example:

callFunctionInJsFile(checkBoxes);

这篇关于在asp.net的背后code创建JavaScript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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