首页产品库评测行情新闻|手机数码笔记本台式机DIY硬件数字家庭数码相机办公外设|软件下载游戏开发|社区

更多

数码相机
MP4
LCD
机箱
音箱

天极网 > 软件频道>ASP.NET+Atlas创建客户端Web应用程序

ASP.NET+Atlas创建客户端Web应用程序

2006-07-28 08:00作者:朱先忠编译出处:ASP.NET责任编辑:方舟

  (六) 在客户端应用程序添加代码

  切换到设计视图,双击生成的Web表单以显示页面相应的代码部分(Default.aspx.cs)。选择Ctrl+A来选择所有的自动生成的代码,并按Delete键清除文档。然后,添加下列代码以消费Amazon ECS服务并且显示搜索结果:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
 protected AWSECommerceService AmazonECS = new AWSECommerceService();
 protected ItemSearch Search = new ItemSearch();
 protected ItemSearchRequest SearchRequest = new ItemSearchRequest();
 protected ItemSearchResponse SearchResponse;
 protected void submitSearch_Click(object sender, EventArgs e)
 {
  Search.AWSAccessKeyId = TxtBAccessKey.Text.ToString();
  SearchRequest.SearchIndex = "Restaurants";
  SearchRequest.Cuisine = ListBoxCuisine.SelectedValue;
  SearchRequest.City = listBoxCity.SelectedValue;
  SearchRequest.Neighborhood = TextBox3.Text.ToString();
  SearchRequest.ResponseGroup = new String[] { "ItemAttributes" };
  Search.Request = new ItemSearchRequest[1] { SearchRequest };
  try
  {
   SearchResponse = AmazonECS.ItemSearch(Search);
   if (SearchResponse.Items == null)
   { labelError.Text = "A Server error has occured."; }
   else
   {
    Items responseItems = SearchResponse.Items[0];
    Item[] response = responseItems.Item;
    if (response != null)
    {
     foreach (Item I in response)
     {
      NoResults.Text = "";
      Label Results = new Label();
      Label Sep = new Label();
      Results.Text = "<strong>" + I.ItemAttributes.Title.ToUpper() + "</strong>" + "<br/>"
+ I.ItemAttributes.Address.Address1.ToString() + "<br/>"
+ I.ItemAttributes.Neighborhood + "<br/>"
+ "Tel:" + " " + I.ItemAttributes.PhoneNumber + "<br/>"
+ "Price Rating:" + " " + priceRating(I.ItemAttributes.PriceRating)+"<br/>"+"<br/>";
      Sep.Text = "<br/>";
      RP1.Controls.Add(Results);
      RP1.Controls.Add(Sep); }
    PriceRange.Text ="Price per person (based on entree, appetizer or salad, one non-alcoholic drink plus tax and tip)";
   }
   else
   {
    NoResults.Text = "No search results found.";
    PriceRange.Text = "";
   }
  }
 }
 catch (Exception ex)
 {
  labelError.Text = ex.Message.ToString();
 }
}
private string priceRating(string str)
{
 if (str=="1"){
  return "under $15";}
 else if(str=="2"){
  return "$15-30";}
 else if(str=="3"){
  return "$30-45";}
 else if(str=="4"){
  return "over $45";}
 else{return null;}
}
protected void listBoxCity_SelectedIndexChanged(object sender, EventArgs e)
{}
protected void ListBoxCuisine_SelectedIndexChanged(object sender, EventArgs e)
{}
}

  (七) 运行应用程序

  1. 为了运行应用程序,在设计视图下打开Default.aspx页面。选择TxtBAccessKey TextBox控件;在Properties窗口中把你的Amazon Web服务存取键ID添加到该控件的Text属性中。

  2. 按F5键以运行该应用程序。

  3. 使用应用程序的过程是相当直接的。从Cuisine:列表框中选择一种cuisine类型,从City:列表框中选择一个城市,然后点击Submit按钮。作为选择,你还可以细化你的搜索。

  (八) 从浏览器中使用Amazon ECS Web服务

  1. 使用一个桥接文件来指定消费远程Web服务的代理类、调用该服务的方法以及如何操作返回的数据。

  2. 使用ScriptManager控件参考桥接文件。

  3. 使用html控件,JavaScript和客户端Atlas数据组件来使用服务即可。

  七、 结论

  Asp.net Atlas是一个创建基于客户端的Web应用程序的框架。这个框架在提供客户端和服务器端API用来创建跨浏览器兼容的AJAX风格的应用程序的同时,还引入了另外一些特征,例如桥接技术,gadget,一个JavaScript声明性脚本模型和扩展,等等。

  总之,本文介绍了该框架的典型使用框架;还通过使用Atlas UpdatePanel控件介绍了部分(Partial)页面生成技术,这是在asp.net Web应用程序中增加AJAX功能和改进用户体验的最简单的方法。

关注此文的读者还看过:

返回软件频道首页

共5页。 上一页12345

软件频道最新更新

热点推荐

天极服务|关于我们|About us|网站律师|RSS订阅|友情合作|加入我们|天极动态|网站地图|意见反馈|MSN/QQ上看天极
Copyright (C) 1999-2012 Yesky.com, All Rights Reserved 版权所有 天极网络