如何通过从服务器端页面,在asp.net客户端功能的价值 [英] How to pass a value from server side page to client side function in asp.net

查看:106
本文介绍了如何通过从服务器端页面,在asp.net客户端功能的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序需要从服务器端(.aspx.cs)的字符串值传递给函数在客户端(的.aspx)页面。

In my application I need to pass a string value from the server side(.aspx.cs) to a function in the client side (.aspx) page.

谁能帮我提供的思路和可能的话样本code?

Can anyone help me by providing ideas and sample code if possible?

推荐答案

如果你的意思是你需要的值传递给一个JavaScript函数,你可以做的就是这样的事情...

If you mean that you need to pass the value to a javascript function, what you can do is something like this...

在.aspx文件:

<script language="javascript" type="text/javascript">
  var stringValue = '<%=GetStringValue();%>';

  // For example:

  alert(stringValue);
</sctipt>

在.aspx.cs文件:

In the .aspx.cs file:

private string GetStringValue()
{
  return "A string value";
}

这将然后显示一个消息框的javascript说的字符串值在页面加载时

This would then show a javascript messagebox saying "A string value" when the page loads

这篇关于如何通过从服务器端页面,在asp.net客户端功能的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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