DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX詳解 >> MagicVS2008 Ajax.NETFrameworkUsage使用
MagicVS2008 Ajax.NETFrameworkUsage使用
編輯:AJAX詳解     

MagicAJax.Net Framework

Usage

Table of Contents

  • Programming
    • >Handling an AJaxCall
    • >Setting an AJax refresh timer
  • Controls
    • >AJaxPanel
    • >AJaxZone
    • >ClIEntEventTrigger
    • >KeyClIEntEventWrapper
    • >AjaxPage and AJaxUserControl
    • >AjaxHtmlAnchor and AJaxHtmlImage
    • >MagicAJax attributes for ASP.Net controls

Programming

Handling an AJaxCall

Depending on the PageStore Mode configuration option, the page's execution cycle will differ significantly (see >Configuration Options). For the default 'NoStore' mode, the page's execution cycle will be the same as a PostBack. You can distinguish if a PostBack or an AJaxCall occured, by checking the return value of theMagicAjaxContext.Current.IsAJaxCallForPage method.

根據PageStore Mode的配制選項,頁面的執行周期會有很大的不同(see >Configuration Options)對於默認的'NoStore' mode,頁面的執行周期將會如同PostBack,你可以進行區分是PostBack 還是AJaxCall發生了,通過檢查MagicAjaxContext.Current.IsAJaxCallForPage方法的返回值

Note: There is a MagicAjaxContext.Current.IsAJaxCallproperty that is true if the http request was originated by an AjaxCall, but the recommended method of checking whether an AJaxCall was invoked is by using IsAJaxCallForPage. If the page is created because of a Server.Transfer call that occured during an AjaxCall, IsAJaxCallForPage will return false so that your page can execute as a normal page request. The AjaxPage.IsAJaxCall property, that makes a call to IsAJaxCallForPage, is provided for convenIEnce (see >AJaxPage).

注意:有一個屬性MagicAjaxContext.Current.IsAJaxCall,如果它為true,那麼http請求是AJaxCall是引起的。但是推舉的方式是使用IsAJaxCallForPage來進行判斷是否是AJaxCall調用。如果頁面被創建是由於Server.Transfer的調用(這個調用在AJaxCall期間發生)IsAJaxCallForPage它將會返回false,因此你的頁面可以做為常規頁面來運行。AjaxPage.IsAJaxCall 屬性(可以引起對IsAJaxCallForPage調用)是為了方便才提供的

MagicAjax sends Javascript code to the clIEnt as a response to an AJaxCall. If you want to send your custom Javascript along with MagicAJax's, you can use the static functions ofAJaxCallHelper. For example:

做為一個AJaxCall的響應MagicAJax發送Javascript code到客戶端,如果你要發送用戶定制的Javascript代碼,可以用AJaxCallHelper中的靜態方法。如:

        private void Button1_Click(object sender, System.EventArgs e)

        {

               AJaxCallHelper.WriteAlert ("Button1 was clicked.");

        }


Setting an AJax refresh timer設定刷新時間

You can use the AjaxCallHelper.SetAJaxCallTimerIntervalmethod to set a page wide timer that will invoke AjaxCalls at the intervals that you define. You can call it either at the initial page request or during an AJaxCall to initiate it or change the interval value. If you call it with an interval value of zero, the timer will deactivate.

你可以使用AjaxCallHelper.SetAJaxCallTimerInterval方法來設定頁面的刷新時間(在這個時間間隔,AJaxCall將會被調用)范圍,你可以在初使化頁面請求時或在AJaxCall調用期間來調用這個方法,如果interval的值為0,則定時器無效

Example:

        private void Page_Load(object sender, System.EventArgs e)

        {

               if (!IsPostBack)

               {

                       // AJax refresh every 10 seconds

                      MagicAjax.AjaxCallHelper.SetAJaxCallTimerInterval(10000);

               }

        }

              

Controls

AJaxPanel

This is the core control of the MagicAjax framework. The PostBack functionality of all the controls that are inside an AJaxPanel will be replaced by an AJax callback (AjaxCall), unless defined otherwise. AJaxPanel works like the ASP.Net Panel, its contents are visible on the designer, you can set all the WebControl attributes to it, change its Visible property etc.

這是個MagicAJax的核心控件,所以在AJaxPanel中的控件的PostBack功能將會被AJax callback進行替換。如果沒有什麼特別的處理,AJaxPanel就如同ASP.Net Panel一樣,它的內容可以在設計器中可視化顯示,你可以設置所有的web控件的屬性或改變它

Its AJaxCallConnection property can be set to:

  • Asynchronous (Default)

The AJaxCall will be invoked in the background

AJaxCall將會在後台調用

  • Synchronous

The clIEnt's browser will wait for the AJaxCall to finish

客戶端browser將會等到AJaxCall完成

  • None

Controls inside the AJaxPanel will invoke a normal PostBack

AJaxPanel中的控件將會調用常規的PostBack

Its ExcludeFlags property determines which form elements should be excluded from posting to the server during an AjaxCall, thus reducing the AJaxCall traffic. It sets the >ExcludeFlags MagicAJax ASP.Net control attribute. A child AjaxPanel automatically "inherits" the ExcludeFlags of its parent AjaxPanel. The child can mark more form elements to exclude through its ExcludeFlags property but it cannot send to the server form elements that have been marked for exclusion by its parent AJaxPanel.

In order to reduce the amount of html needed to send to client, AjaxPanel defines individual 'html holders'. If the html of a holder changes during an AjaxCall, MagicAjax sends the whole html of the holder so that it can be reflected to the clIEnt's browser. Every immediate WebControl child of an AjaxPanel is considered a separate holder, and one extra holder is defined for the literal and HtmlControls content of the AjaxPanel. Thus, if the html of a WebControl, that is enclosed inside an AJaxPanel, changes, only the Html of the particular WebControl will be sent to the clIEnt.

為了降被發送到客戶端的Html的代碼量,AJaxPanel定義了單獨的Html占位符,如果Html占位符在AJaxCall期間改變了,MagicAJax發送整個占位符的Html來反應到客戶端。每一個直接的AJaxPanel中的子控件被應用分別的占位符,定義占位符是為了literal and HtmlControls content of the AJaxPanel.,因此如果webcontrol(在AJaxPanel中)中的Html改變了,僅僅特定的控件將會發送到客戶端

An AjaxPanel (child AjaxPanel) that is inside another AjaxPanel (parent AjaxPanel), define its html holders separately from its parent. The parent AjaxPanel will ignore the html of the child AjaxPanel; only the child AjaxPanel will be responsible for reflecting its holders on the client. Thus, you can reduce the traffic of AjaxCalls, by adding many AjaxPanels that define more and smaller html holders. For example, if you put a table inside an AjaxPanel and change one of its cells during an AjaxCall, the complete html of the table is going to be sent to the clIEnt. On the other hand, if you add an AJaxPanel for each cell, only the Html of the contents of the changed cell will be sent to the clIEnt.

一個AJaxPanel(子AJaxPanel)在另一個AJaxPanel(父AJaxPanel)中。這個子AJaxPanel將會定義它的Html占位符與父AJaxPanel分離.父AJaxPanel將會忽略子AJaxPanel的Html占位符,僅僅子AJaxPanel負責更新它的內容到客戶端。因此你可以將低流量,通過添加更多的AJaxPanel來定義更多的更小的Html占位符。例如,如果你想把table入到AJaxPanel中,如果在AJaxCall調用過程中改變了,則整個table的Html都會被發送到客戶端,另一種方式,如果你添加AJaxPanel到cell級別,如果內容變了,僅僅單元格的內容發送到客戶端

In order to monitor the traffic of AJaxCalls that your page is producing, you can enable the >tracing configuration option.你可以通過tracing功能來進行跟蹤


AJaxZone

It's an AjaxPanel that has the MagicAJax attribute >AJaxLocalScope set to true. It is provided for convenIEnce and readability. When an AjaxCall is invoked from a control inside an AjaxZone, only the values of the form elements that are contained inside this AjaxZone will be sent to the server and the server will check for changes and "reflect" only the AjaxPanels that are inside the AJaxZone. This helps reduce theAJax traffic and speed up a bit the server's response. It's intented for isolated and independent portions of a page, like UserControls.

An AjaxZone can contain other AjaxZones. A control belongs to the AJaxZone that is its immediate parent.

這是一個AJaxPanel的屬性AJaxLocalScope值為true的AJaxPanel。它提供了便利和可讀性,當一個AJaxCall是在AJaxZone內部的控件調用時,僅僅包含在這個AJaxZone中的元素值被發磅到服務器,服務器將會check這些改變,然後更新到客戶端的AJaxZone中,這個有助於降低數據的流量,和服務器的反應速度,這個的目的是使化成為一個獨立的部分,更像一個用戶控件


ClIEntEventTrigger觸發器

Captures a client event of a control. The EventName property must be set to the client event (i.e. "focus", "change", etc.) and the ControlID property must be set to the ID of the control whose event you want to capture. The AjaxCall that will be invoked is dependent at the ClientEventTrigger's placement, not the placement of ControlID's control. For example, if the ClIEntEventTrigger is inside an AjaxPanel an AjaxCall will be invoked even if the ControlID's control is not inside an AJaxPanel. The ClIEntEventTrigger must be inside the same NamingContainer (i.e. UserControl) as the ControlID's control.

捕獲一個控件的客戶端事件,事件的名稱屬性必須設定成客戶端的事件如(i.e. "focus", "change", etc.)並且ControlID屬性必須設定成一個控件的ID(這個控件將會觸發這個事件),例如,ClIEntEventTrigger 在AJaxPanel內,AJaxCall會被調用,即使那個ControlID所標識的控件不在AJaxPanel中。The ClIEntEventTrigger must be inside the same NamingContainer (i.e. UserControl) as the ControlID's control.


KeyClIEntEventWrapper包裝器

Captures the KeyPress, KeyDown, and KeyUp client events of its inner controls. The KeyPress event has the IE behaviour across all browsers (invoked when a character is typed or Enter is pressed).

捕獲內部控件的按鍵事件,


AjaxPage and AJaxUserControl用戶控件

Making your pages and usercontrols inherit from AjaxPage and AjaxUserControl is not required; they're provided only for convenIEnce. They expose the MagicAJax's stored page events (see >Session/Cache PageStore modes) and provide theIsAJaxCall property that makes a call to MagicAjaxContext.Current.IsAJaxCallForPage.

IsAJaxCall屬性將會對MagicAjaxContext.Current.IsAJaxCallForPage.方法進行調用


AjaxHtmlAnchor and AJaxHtmlImage

These controls are intented to be used only for the >Session/Cache PageStore modes. When these modes are selected, ASP.Net's HtmlAnchor and HtmlImage loose their hrefand src attributes during an AjaxCall. AjaxHtmlAnchor and AJaxHtmlImage can be used in their place.


MagicAJax attributes for ASP.Net controls

You can add special attributes to ASP.Net controls that define how they will be handled by MagicAJax:

你可以添加特別的屬性到ASP.Net控件中,來確定這些控件如何被MagicAJax處理

  • AJaxCall ("Async" or "Sync" or "None")

If you add the AJaxCall attribute with "Async"/"Sync" value to a control that has PostBack functionality (i.e. Button, LinkButton, CheckBox, etc.) the PostBack functionality of the control will be replaced by AJax functionality, even if it is not contained inside an AJaxPanel. If you add theAJaxCall attribute with "None" value to a control that is inside an AjaxPanel, the control will perform a PostBack instead of an AJaxCall. By adding the AJaxCall attribute, you override the AjaxCallConnection property of its parent AjaxPanel (if the AJaxPanel is set to Asynchronous, you can add AJaxCall with "sync" value to a control to make it perform a synchronous AJaxCall). The effect of the AJaxCallattribute is applIEd to all the children of the control, so if you add it to a plain ASP.Net Panel, all the controls that are contained inside this Panel will get the effect of theAJaxCall attribute.

如果你添加屬性"Async"/"Sync"值 ,則具有PostBack功能的控件,則會用AJax功能所代替,即使它不包含在AJaxPanel中。
如果你加天屬性為None值,到控件(這個控件中AJaxPanel中)則這個控件執行Postback 而不是AJaxCall.
通過添加AJaxCall屬性你可以覆蓋父AJaxPanel的AJaxCallConnection屬性。(如果AJaxPanel是Asynchronous,你可以設定AJaxCall為sync合控件執行synchronous AJaxCall).AJaxCall的效果被應用到所有的子控件。

 

 

 

 

  • ExcludeFromPost ("true" or "false")

When an AJaxCall is invoked, the clIEnt sends the values of the form elements to the server as POST data. If there is a control that is used only to display information and not to get input from the user, you can add theExcludeFromPost attribute with "true" value and the value of this control will not be sent to the server. For example, if your page contains a readonly TextBox that is used to display chat messages, sending its contents for every AJaxCall is unnecessary traffic; you can avoid it by using the ExcludeFromPost attribute.

對於僅僅顯示值的控件的數據不需要發送的客戶端,你可以設定此屬性來防止無用的數據被提交到後台。

  • AJaxLocalScope ("true" or "false")

Makes the control behave like an >AJaxZone.

  • ExcludeFlags (expression)

Determines which form elements will be excluded from posting to server during an AjaxCall. These form elements will be excluded when an AJaxCall is invoked from the control or one of its children. It should be set to an arithmetic expression that has an integer as a result. The Javascript constants excfVIEwStateexcfFingerprints,excfUserHiddenexcfAllHiddenexcfFormElements,excfAllElements can be used for convenIEnce.

確定哪個form元素可以被排除發往服務器。在AJaxCall調用時這個form元素將會被排除。它有一組運算表達式,

Example:

  <ASP:button excludeflags="excfFormElements | excfVIEwState" ...>

All the attributes can be added inside the control's tag statement or by code. Their values, and consequently their function, can be changed during an AJaxCall.

所有的屬性可以通過標記方式或代碼方式設定,它們的值和隨後的功能在AJaxCall調用時被改變

Example:

        Button1.Attributes["AJaxcall"] = "async";

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved