从通过javascript code后面访问的变量 [英] Access variable from code behind via javascript

查看:124
本文介绍了从通过javascript code后面访问的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code,我想回到一个JavaScript变量t:

I have the following code that I want to return to a variable "t" in javascript:

背后code:

Public Shared Function GetSomeText() As String
  Dim result = "This is from code behind"
  Return result
End Function

在JavaScript来电变量:

Caller variable in javascript:

//This is not working like that, I think
    var t = GetSomeText();

所以,我怎样才能使变量t,从功能GetSomeText从得到结果code-后面?

So, how can I make variable "t" get the "result" from Function GetSomeText from code-behind?

感谢您。

推荐答案

试试这个 - 假设此页面上的公共方法。这将调用该方法GetSomeText()页面类,然后做数据的Response.Write()页面,因为它是被渲染。结果应该结束了在你的JavaScript中的单引号之间。

Try this -- assuming that this a public method on the page. This will call the method GetSomeText() on the page class and then do a Response.Write() of the data to the page as it's being rendered. The result should end up between the single quotes in your javascript.

 var t = '<%= GetSomeText() %>';

这篇关于从通过javascript code后面访问的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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