代码之家  ›  专栏  ›  技术社区  ›  Arnkrishn

在jQuery中访问ASP.NET服务器变量

  •  6
  • Arnkrishn  · 技术社区  · 16 年前

    在Page_Load()函数中,我填充了一个arraylist和一个哈希表。我需要读取$(document).ready(function(){…}中的值。

    干杯

    4 回复  |  直到 16 年前
        1
  •  5
  •   ram    16 年前

    您可以使用PageMethods从JS调用您的aspx页面。 Here is a nice article 关于如何在jQuery中使用page方法。您可以在page方法中返回“whatever”。如果要在将服务器端对象传递到客户端之前序列化它们,可以将它们序列化为JSON。 Here is an example "success: function(msg){//do something}" )并相应地更新您的HTML

        2
  •  0
  •   TheVillageIdiot    16 年前

    你可以用 Page.ClientScript

    有关详细信息,请参阅 MSDN

        3
  •  0
  •   Hiyasat    16 年前

    您可以在服务器端创建page.method,并在返回值数组的客户端脚本中调用它

    by adding 
    
    <scriptManager EnablePageMethods="true">
    
    in the server side you create a function that return an array of values
    ex:  GetArrayResult()
    
    
      if you intersting in this i will give you the rest of example
    
        4
  •  0
  •   David Robbins    16 年前

    JSON.Net 将帮助您将哈希表和数组序列化为JSON,您可以将它们存储在隐藏字段中。然后在客户端,您可以使用以下命令将字符串反序列化为javascript变量:

    var array = JSON.parse($('#hiddenTextField').val());