zoukankan      html  css  js  c++  java
  • UpdateControl,ScriptManager,TimerControl,AutoCompleteExtender

    http://atlas.asp.net/docs/atlas/doc/controls/default.aspx

    Client-side Components

    Top
    In some of the preceding examples in this page, you have seen the use of a component such as popup. There are other components within the ASP.NET "Atlas" framework. The following sample shows the Web.Timer component used both programmatically and declaratively. Components are not bound to markup elements and so should be regarded as non-UI objects.
    Using ASP.NET "Atlas" Components
    Run Sample View Source

    ASP.NET "Atlas" Server Controls

    Top
    The ASP.NET "Atlas" framework allows you to develop rich UI applications using client controls and components in a declarative or a programmatic form. You can add similar client functionality to new or existing ASP.NET applications using the ASP.NET "Atlas" server controls. You can:
    • Specify partial page rendering in place of a normal postback using UpdatePanel controls to specify rendering and update behavior of regions of the Web page.
    • Use control extenders to add pre-written client behavior to ASP.NET controls, such as adding the autocomplete behavior to the ASP.NET TextBox control.
    • Create custom extenders that define new behaviors for server controls. Page developers can then add your extenders to server controls and get client behavior without writing ASP.NET "Atlas" script or JavaScript.

    UpdatePanel Controls

    Top
    In typical ASP.NET 2.0 applications, when a postback occurs, the page is re-rendered. This causes the page to flash in the browser. On the server, during postback, the page lifecycle executes. This ultimately raises the control event that caused the postback and runs the event handler (for example, a Button control's Click handler).

    The ASP.NET "Atlas" UpdatePanel control eliminates the full page refresh. The UpdatePanel control is used to mark a region in the page that will be updated when a postback occurs, but without the traditional postback behavior in the client. On the server, the page still handles the postback and runs normally, such as raising event handlers. But during the final rendering of the page, only the regions defined by UpdatePanel controls are created. This is referred to as partial rendering.

    The following example demonstrates the use of an UpdatePanel control.

    Using the ASP.NET "Atlas" UpdatePanel Control
    Run Sample View Source

    UpdatePanel controls require a ScriptManager control, which is responsible for creating relevant ASP.NET "Atlas" script references in the client and for managing the partial rendering model. The ScriptManager control manages partial page updates and allows only the UpdatePanel controls and their children to render. For more information, see the ASP.NET "Atlas" ScriptManager Control section.

    ASP.NET  
                <atlas:ScriptManager runat="server" ID="ScriptMgr" EnablePartialRendering="true">
                ..
                </ScriptManager>
                <atlas:UpdatePanel runat="server" ID="UpdatePanel2" Mode="Always">
                <ContentTemplate>
                <asp:label runat="server" Text="Keep changing me!" ID="Label1" />
                ..
                </ContentTemplate>
                ..
                </atlas:UpdatePanel>
                

    UpdatePanel controls have ContentTemplate elements that act as a container for content, generally ASP.NET server controls. The ContentTemplate specifies the markup that will be rendered in a partial update.

    The Mode property specifies when the UpdatePanel refreshes its contents. If the Mode property is set to Always, the contents of the panel are refreshed during every postback. If the Mode property is set to Conditional, the panel is rendered on the server based on one or more triggers, such as when specified property values change or when specified events occur. This optimizes the markup sent to the client during postback.

    You can nest UpdatePanel controls. In that case, you can associate a trigger in the child UpdatePanel control with a control property or event in the parent UpdatePanel control.

    Using Triggers with UpdatePanel Controls

    Top
    When the UpdatePanel control's Mode property is set to Conditional, the panel's markup is rendered only in response to a trigger. The UpdatePanel control contains a collection of triggers. There are two types of triggers:
    • ControlEventTrigger. This defines a trigger associated with a specific event (EventName) raised by a control on the page (ControlID). When the event is raised on the associated control, the trigger is fired and the contents of the UpdatePanel control will be rendered during the partial rendering of the page on the server.
      ASP.NET  
                      <asp:Button runat="server" ID="btnTrigger" Text="Trigger"
                      OnClick="btnTrigger_Click" />
                      ..
                      <atlas:UpdatePanel runat="server" ID="UpdatePanel2" Mode="Conditional">
                      <Triggers>
                      <atlas:ControlEventTrigger ControlID="btnTrigger" EventName="Click" />
                      </Triggers>
                      ..
                      </atlas:UpdatePanel>
                      
    • ControlValueTrigger. This defines a trigger associated with a specific property (PropertyName) for control on the page (ControlID). When the property value changes on the associated control, the trigger is fired and the contents of the UpdatePanel control will be refreshed during postback.
      ASP.NET  
                      <asp:TextBox ID="txtMessage" runat="server" />
                      ..
                      <atlas:UpdatePanel runat="server" ID="UpdatePanel2" Mode="Conditional">
                      <Triggers>
                      <atlas:ControlValueTrigger ControlID="txtMessage" PropertyName="Text" />
                      </Triggers>
                      ..
                      </atlas:UpdatePanel>
                      

    The following example demonstrates the use of triggers with an UpdatePanel control and illustrates various update modes.

    Using the ASP.NET "Atlas" UpdatePanel Control with Triggers
    Run Sample View Source

    Changes in an UpdatePanel control can be triggered by the new ASP.NET "Atlas" TimerControl, which enables you to refresh an UpdatePanel control at a given interval.

    The ASP.NET "Atlas" ScriptManager Control

    Top
    The ScriptManager control manages several pieces in the ASP.NET "Atlas" runtime. In particular, it writes to the rendered page a number of script references that are required for ASP.NET "Atlas". (These are implicit script references; additional references can be added using the Scripts collection.) The ScriptManager control is also responsible for much of the work in managing partial page rendering for UpdatePanel controls. UpdatePanel controls interact with the ScriptManager control to detect a partial rendering request and then determine whether to render.
    ASP.NET "Atlas"  
                ..
                <atlas:ScriptManager runat="server" ID="UpdatePanel2"
                EnableScriptComponents="True" EnablePartialRendering="True">
                <Scripts>
                <atlas:ScriptReference Name="AtlasUIMap" />
                <atlas:ScriptReference Path="~/MyScripts/MyScript.js" />
                </Scripts>
                <Services>
                <atlas:ServiceReference Path="ComplexService.asmx" />
                </Services>
                </atlas:ScriptManager>
                

    When the ScriptManager control's EnableScriptComponents property is true, the control instructs ASP.NET to reference a .js library that contains not only the JavaScript type system, but also definitions for the client UI components and behaviors. When the property is set to false (the default), the page references a runtime library only. This is more lightweight and optimum when there is no need to also download the UI components and behaviors for the page.

    The EnablePartialRendering property determines how the ScriptManager control manages partial page rendering. When the property is set to true, the ScriptManager control performs many operations in generating and managing the partial rendering of the Web page with UpdatePanel controls. When the property is set to false, partial page rendering is disabled and only regular postbacks are supported.

    The Services property is a collection of JavaScript proxies in the client. For more information, see the Services QuickStart sample.

    The Scripts property is a collection of ScriptReference controls. These allow you to optionally include other ASP.NET "Atlas" scripts such as AtlasUIMap.js or custom scripts. You can define the browser for which the reference should be rendered. The ScriptReference control's properties are:

    • Name The name of one of the ASP.NET "Atlas" framework script files. The enumeration FrameworkScriptName can be used in custom controls that need to register a script requirement with the ScriptManager control.
    • Path The location of a custom script.
    • Browser The browser type for the reference to be rendered.

    The ScriptManager control will rebase any script references to the parent Web page. If you want to use the ASP.NET "Atlas" debug scripts, you can set debug="true" in the <compilation> element of the Web.config file. (Setting debug="true" in @ Page directives for debug scripts is not currently supported.) Scripts are loaded from the following location:

    ~/scriptlibrary/atlas/debug/... - for debug scripts
    ~/scriptlibrary/atlas/release/... - for release scripts

    Only one ScriptManager control is allowed per page. In master-page scenarios, if the master page and content page need to reference a different set of scripts, the master page defines a ScriptManager control and the content page can define a ScriptManagerProxy control. The ScriptManagerProxy control is similar to the ScriptManager control; it helps to separate the scripts required only by a specific content page from the scripts defined in the master page.

    The following example demonstrates the use of a ScriptManagerProxy control in a master page and content page.

    Using the ASP.NET "Atlas" ScriptManagerProxy Control with Master Pages and Content Pages
    Run Sample View Source

    Control Extenders

    Top
    Control extenders provide a way to attach client functionality to ASP.NET server controls. The following sample demonstrates the use of AutoCompleteExtender to add auto-completion functionality to a TextBox control in an ASP.NET page.
    ASP.NET 'Atlas'  
                <asp:TextBox ID="TextBox1" runat="server" />
                ..
                <atlas:AutoCompleteExtender runat="server" ID="autoComplete1">
                <atlas:AutoCompleteProperties ServicePath="AutoComplete.asmx"
                ServiceMethod="GetCompletionList"
                TargetControlID="TextBox1" />
                </atlas:AutoCompleteExtender>
                

    A control extender defines a collection of extender properties. Each property adds the extender functionality to a specified target control (TargetControlID). This means that you can use one control extender for multiple controls on the page. ASP.NET "Atlas" includes the following control extenders:

    • AutoCompleteExtender. Adds auto-completion and drop-down list functionality to a control. The extender has AutoCompleteProperties that define specific functionality.
    • DragOverlayExtender. Adds functionality to enable drag-and-drop behavior for specified sections of the Web page.
    Using AutoCompleteExtender and Other Server Controls
    Run Sample View Source

    Control extenders write custom ASP.NET "Atlas" scripts to the client to add functionality such as the behaviors and actions described earlier in this section. For example, an AutoCompleteProperty extender creates the autoComplete behavior.

    TimerControl

    Top
    The ASP.NET "Atlas" TimerControl server control enables you to perform certain operations based on elapsed time. The following example demonstrates its use with an UpdatePanel control.
    ASP.NET 'Atlas'  
                <atlas:TimerControl runat="server" Interval="15000" ID="tickerTimer" OnTick="tickerTimer_Tick" />
                ..
                <atlas:UpdatePanel runat="server" ID="UpdatePanel1">
                <Triggers>
                <atlas:ControlEventTrigger ControlID="tickerTimer" EventName="Tick" />
                </Triggers>
                ...
                </atlas:UpdatePanel>
                

    The TimerControl has an Interval property (set in milliseconds) used to set the duration for a tick. It can also raise a Tick event, which you can handle for custom operations that occur at the defined interval. The above sample demonstrates working with the UpdatePanel control based on the tick event.

  • 相关阅读:
    共享内存
    用system v消息队列实现回射客户/服务器程序
    消息队列
    在一个递增数组的rotate变换中找target
    栈(Stack)和队列(Queue)是两种操作受限的线性表。
    new与malloc的10点区别(转)
    如何在Ubuntu中安装安全更新
    如何使用Mod_Security和Mod_evasive模块保护Apache 提升DDOS防御力
    如何在Nginx上修复502 Bad Gateway错误
    如何在Ubuntu 20.04上使用Apache和mod_wsgi运行Python脚本?
  • 原文地址:https://www.cnblogs.com/stswordman/p/447529.html
Copyright © 2011-2022 走看看