Ajax控制項之ScriptManager與UpdatePanel用法

來源:互聯網
上載者:User

標籤:

公司項目用到UpdatePanel,完全不明所以。

好在賴壘大神對俺的細心講解,寫個日誌,以作紀念。

作用:用於頁面局部重新整理!不干擾其他控制項內容!

1.首先在頁面申明<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
  註解:
      1, ScriptManager(指令碼控制器)是asp.net ajax存在的基礎.
      2, 一個頁面只允許有一個ScriptManager,並且放在其他ajax控制項的前面.
      3,ScriptManager掌管著用戶端Ajax頁的多有指令碼,並在頁面中註冊Ajax類庫,用來實現頁面的局部更新和對Web服務的調用.

 

2. body內容部分加入以下代碼

<asp:UpdatePanel ID="UpdatePanel_1" ChildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
     <Triggers>
             <asp:AsyncPostBackTrigger ControlID="btnGetCode"  EventName="Click" />
      </Triggers>
      <ContentTemplate>
               <asp:Label ID="lblResult" runat="server" Text="Label"></asp:Label>
        </ContentTemplate>
</asp:UpdatePanel> 
  註解:控制項ID名為:“btnGetCode”的控制項,當其觸發Click事件時,將非同步執行該控制項綁定的Click對應的函數,函數執行結果,回顯在<ContentTemplate></ContentTemplate>兩個元素的裡面的控制項之內!

 

 

2.後台btnGetCode_Click部分加入以下代碼,只需要給lblResult賦值就行

Ajax控制項之ScriptManager與UpdatePanel用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.