日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > web前端 > jquery > 使用jQuery,CSS,JSON和ASP.NET創建新聞輪換控件

使用jQuery,CSS,JSON和ASP.NET創建新聞輪換控件

來源:程序員人生   發布時間:2013-12-28 19:41:17 閱讀次數:3682次
這個新聞輪換控件能在網頁上的同一個地方顯示幾條新聞。新聞被拆開幾頁,為了放置在一個指定的區域。每一頁也能包含一對新聞列表。 通過點擊底部的頁碼,能夠在不同的頁面之間導航,點擊頁的每個新聞項,就能查看新聞的詳細信息。新聞能像幻燈片一樣去查看。它提供自動切換下一個(幻燈片)功能,以及過渡的樣式。

使用JQuery為了:

    1、對web server進行JQuery Ajax Request請求,得到JSON格式新聞
    2、綁定數據(JSON格式的新聞)到HTML控件
    3、在數據binding之后設置控件的樣式
    4、新聞之間的導航
    5、用戶交互
    6、改變和設置樣式
    7、實現javascript的效果
新聞滾動控件使用ASP.NET從新聞存儲(例如數據庫,xml文件,rss,...)匯集新聞。將它轉化成指定類型(NewsItem)。 然后將newsItem對象的集合轉化成JSON格式的數據,作為新聞的數據來源發送到客戶端。

這個控件使用開源的Json.NET類庫,它使JSON格式的數據在.NET中使用更加的方便。這個類庫的關鍵的功能包括一個靈活的JSON序列化,能快速的將.net類轉換成JSON ,將JSON轉換成.net類。了解更多的Json.NET類庫(代碼。示例,和文檔),點擊這里。

新聞滾動控件主要使用 jQuery Image Rotator sample的思想。  通過Soh Tanaka 的描述,你能找到更多的關于如何去構造一個滾動的圖片效果。

這個新聞滾動控件使用 jQuery Cycle 插件來旋轉新聞插件,它是一個輕量級的幻燈片插件,在頁面上,這個插件為開發者提供強大的旋轉能力來輪轉不同類型的HTML控件。了解更多的 jQuery Cycle 插件,點擊這里。
你需要使用該控件:
1、引用必要的資源到你的HTML頁面(.aspx頁面):
<%@ Register Src="~/TopNews.ascx" TagName="TopNews" TagPrefix="ctrl" %>
<body>
<form id="form1" runat="server">
<div>
<ctrl:TopNews runat="server" id="TopNews1" />
</div>
</form>
</body>
2、在你的.aspx頁面中注冊和嵌入TopNews.ascx控件。
<%@ Register Src="~/TopNews.ascx" TagName="TopNews" TagPrefix="ctrl" %>
<body>
<form id="form1" runat="server">
<div>
<ctrl:TopNews runat="server" id="TopNews1" />
</div>
</form>
</body>

3、 一開始控件通過調用DOM尾部的JavaScript 的TopNews() 函數。 這個函數向服務端發送一個Ajax請求。得到JSON格式的新聞。然后將新聞綁定到控件上面。 在綁定之后,設置控件的樣式,接著滾動新聞。

<script type="text/javascript">
new TopNews('#Container', 7,true,6000);
</script>

TopNews function parameters:
parameter 1(objRoot): newsRotator control container (a jquery selector),
the control uses this parameter as a prefix (root object) of every
jquery selector inside the control.this prefix helps to have multiple instance
of control in the page without any worry of jquery selection conflict.
parameter 2(newsCountPerPage): number of news items in a page.
parameter 3(viewSubtitle): a boolean value makes subtitle section
of the control enable or disable. the rest of the news titles shows
in the subtitle section randomly at the bottom of the current page.
parameter 4(Interval): news rotation (slideshow) interval in millisecond.
4、需要一個服務端來收集新聞。 然后將新聞轉化成JSON格式,將它發送到客戶端。 

在客戶端,我們使用Jquery發送一個Ajax請求去調用服務端的方法。

//call ASP.NET page method asynchronous (send and recives data in JSON format)
PageMethod: function(fn, paramArray, successFn, errorFn) {
var pagePath = window.location.pathname;
var that = this;
//Call the page method
$.ajax({
type: "POST",
url: pagePath + "?Callback=" + fn,
contentType: "application/json; charset=utf-8",
data: paramArray,
dataType: "json",
//that is a reference to the object calling this callback method
success: function(res) { successFn(res, that) },
error: errorFn
});
}

在服務器端,我們像下面這樣去實現:

protected void Page_Load(object sender, EventArgs e)
{
// *** Route to the Page level callback 'handler'
this.HandleCallbacks();
}

// Callback routing
public void HandleCallbacks()
{
if (string.IsNullOrEmpty(Request.Params["Callback"]))
return;

// *** We have an action try and match it to a handler
switch (Request.Params["Callback"])
{
case "fetchAllNews":
this.FetchAllNews();
break;
}

Response.StatusCode = 500;
Response.Write("Invalid Callback Method");
Response.End();
}

public void FetchAllNews()
{
List<NewsItem> lsttst = new List<NewsItem>();
lsttst.Add(new NewsItem("Environment of Australia",
this.ResolveUrl("~/img/news1.jpg"),
this.ResolveUrl("~/img/news1_thumb.jpg"),
"Australia has a rich variety of endemic legume
species that thrive in nutrient-poor soils because
of their symbiosis with rhizobia bacteria and mycorrhizal fungi",
DateTime.Now.ToShortDateString()));
lsttst.Add(new NewsItem("Economy of Australia",
this.ResolveUrl("~/img/news2.jpg"),
this.ResolveUrl("~/img/news2_thumb.jpg"),
"The Australian dollar is the currency of the
Commonwealth of Australia, including Christmas Island,
Cocos (Keeling) Islands, and Norfolk Island",
DateTime.Now.ToShortDateString()));
lsttst.Add(new NewsItem("Demographics of Australia and
Immigration to Australia", this.ResolveUrl("~/img/news3.jpg"),
this.ResolveUrl("~/img/news3_thumb.jpg"),
"Most of the estimated 21.8 million Australians are
descended from colonial-era settlers and post-Federation
immigrants from Europe", DateTime.Now.ToShortDateString()));
lsttst.Add(new NewsItem("Religion in Australia",
this.ResolveUrl("~/img/news4.jpg"),
this.ResolveUrl("~/img/news4_thumb.jpg"),
"Australia has no state religion. In the 2006 census,
64% of Australians were listed as Christian of
any denomination, including 26% as Roman Catholic and
19% as Anglican", DateTime.Now.ToShortDateString()));
lsttst.Add(new NewsItem("Education in Australia",
this.ResolveUrl("~/img/news5.jpg"),
this.ResolveUrl("~/img/news5_thumb.jpg"),
"School attendance is compulsory throughout Australia.
In most Australian States at 5–6 years of age all children
receive 11 years of compulsory education",
DateTime.Now.ToShortDateString()));

Response.ContentType = "application/json; charset=utf-8";
Response.Write(JavaScriptConvert.SerializeObject(lsttst));
Response.End();
}

代碼:TopNews.rar

參考原文:http://www.codeproject.com/KB/applications/TopNews.aspx

雅虎新聞輪換控件:http://www.codeproject.com/KB/applications/YahooNewsRotator_.aspx

作者:朱祁林 出處:http://zhuqil.cnblogs.com
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
為碼而活
積分:4237
15粉絲
7關注
欄目熱點
關閉
程序員人生
主站蜘蛛池模板: 亚洲老板91色精品久久 | 九色精品| 欧美视频一区二区在线观看 | 成人在线日韩 | 九九热av | 毛片免费高清 | 国产一区二区三区在线观看视频 | 成人av在线网站 | 欧美一区二区三区在线观看视频 | av网站黄色| 欧美特黄aaaaaaaa大片 | 国产69久久精品成人看 | 污网站在线 | 国产在线观看一区二区三区 | www激情com | 国产第一精品 | 91一区二区 | 欧美专区一区二区三区 | 国产一二| 日韩中文在线观看 | 国产亚洲精品久 | 免费一区二区视频 | 日韩a级毛片免费看 | 婷婷激情综合 | 在线看一区二区 | 国产一区二区三区免费在线观看 | 国产精品成人一区二区网站软件 | 999久久国精品免费观看网站 | 在线中文字幕av | 视频在线一区二区 | 国产天堂在线 | 青草精品 | 麻豆精品国产91久久久久久 | 视频一区二区三区在线观看 | 日韩精品视频在线播放 | 亚洲成人18 | 免费黄色在线网站 | 成人免费一区二区三区视频网站 | 成人福利午夜 | 九九精品视频在线 | 国产h在线 |