我如何执行获取数据c#代码page_load()使用jquery

本文关键字:page 代码 load jquery 使用 获取 何执行 执行 数据 | 更新日期: 2023-09-27 18:17:19

console application c# code转换为asp.net应用程序,将代码添加到Page_Load()事件中。它从Azure Table获取数据,并希望使用simple html在页面上显示它,

Index.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        // Retrieve the storage account from the connection string.
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting("StorageConnectionString"));
        // Create the table client.
        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
        // Create the CloudTable object that represents the "DeviceData" table.
        CloudTable table = tableClient.GetTableReference("DeviceData");
        // retrive data
        TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>();
        foreach (CustomerEntity entity in table.ExecuteQuery(query))
        {
            // bind data to simple html table 
            //Response.Write("{0}, {1}'t{2}'t{3}", entity.PartitionKey, entity.RowKey,
            //                    entity.Email, entity.PhoneNumber);
        }
    }

CustomerEntity.cs

public class CustomerEntity : TableEntity
{
    public CustomerEntity(string lastName, string firstName)
    {
        this.PartitionKey = lastName;
        this.RowKey = firstName;
    }
    public CustomerEntity() { }
    public string Email { get; set; }
    public string PhoneNumber { get; set; }
}

如何在html页面上显示数据?

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    Show Data here
</body>
</html>

我如何执行获取数据c#代码page_load()使用jquery

您可以创建.aspx页面,而不是Page_Load方法使用单独的WebMethod,可以从jquery调用来查找数据。

参考URL,它用codedemo的示例很好地解释了这一点。

http://www.aspsnippets.com/Articles/Return-JSON-data-object-from-WebMethod-PageMethod-in-ASPNet-using-C-and-VBNet.aspx