經常去codeproject的肯定見過,最近上面發布了一套非常好用的Ajax伺服器控制項目前評價已經很高了
51 votes for this article. |
|
Popularity: 8.06. Rating: 4.72 out of 5. |
一、設計思路簡單清晰
我們以往的使用的架構或自己直接使用xmlhttp直接實現Ajax都難免要寫一些javascript指令碼,而這個最大的亮點(本來想用賣點的,但是人家是開源項目OpenSource project)就是使用時不一定要書寫js指令碼,使用成本極低,昨天仔細觀察了一下他的部分源碼,覺得作者的思路的確不錯,簡單明了;嚴格意義上講這不是套架構,而是封裝良好的控制項,而且感覺比微軟將要推出的atlas控制項簡單,或許使用前幾天發布原始碼的AjaxPro可以編寫出這麼一套控制項也沒什麼難的;
二、使用簡單
以他上面最簡單的demo:Introduction using buttons and labels 為例
他的步驟是: Steps
1.Add a Register directive to the top of your page:
<%@ Register TagPrefix="anthem" Namespace="Anthem" Assembly="Anthem" %>
2.Add an anthem:Button control to your page:
<anthem:Button id="button" runat="server" Text="Click Me!" />
3.Add an anthem:Label control to your page:
<anthem:Label id="label" runat="server" />
4.Add a handler for the button's Click event either by double-clicking on the button in the designer or by adding an OnClick attribute to the button's tag:
<anthem:Button id="button" runat="server" Text="Click Me!" OnClick="button_Click" />
5.Implement the handler in your code behind class or in a server-side script block in your page. Set the Text property like a normal Label control but make sure you set the UpdateAfterCallBack property to true or you won't see the change reflected on the page:
<script runat="server">
void button_Click(object sender, EventArgs e)
{
label.Text = DateTime.Now.ToString();
label.UpdateAfterCallBack = true;
}
</script>
後來我覺得前1234步其實不需要,在其源碼的每個控制項命名空間上加上 [assembly: TagPrefix("Anthem", "Anthem")]
也就省了,但是作者為什麼不加,不得其解,至於5步的button_Click指令碼,可以寫到cs指令碼中,豈不是與一般控制項一樣?
三、支援vs2003和vs2005兩種版本
代碼中有了很多宏,同時支援兩個版本!
有興趣去下來看看,相信能受益……
http://hedonister.cnblogs.com/archive/2006/02/22/335272.html