讓UserControl成為Asp.Net ajax控制項

來源:互聯網
上載者:User

很多時候,我們需要用到User Control,將部份UI或商務邏輯封裝,下面將UserControl封裝成Asp.Net ajax 控制項:

簡單樣本:

(ASCX) 這一段代碼就不解釋了:

 1 <%@ Control Language="C#" AutoEventWireup="true"  CodeFile="LoginPanel.ascx.cs" Inherits="LoginPanel" %>
 2 <table>
 3     <tr>
 4         <td>
 5             Login Name:
 6         </td>
 7         <td>
 8             <asp:TextBox ID="UserName"  Ruant="Server"></asp:TextBox>
 9         </td>
10     </tr>
11     <tr>
12         <td>
13             Password:
14         </td>
15         <td>
16             <asp:TextBox ID="Password" TextMode="Password"  Ruant="Server"></asp:TextBox>
17         </td>
18     </tr>
19 </table>

(LoginPanel.js)

 1 <script type="text/javascript">
 2     /// <reference name="MicrosoftAjax.js"/>
 3     Type.registerNamespace("CsharpFarmer");
 4     CsharpFarmer.LoginPanel= function(element) {
 5         CsharpFarmer.LoginPanel.initializeBase(this, [element]);
 6         this.userName = null;
 7         this.password = null;
 8     }
 9     CsharpFarmer.LoginPanel.prototype = {
10         initialize: function() {
11             CsharpFarmer.LoginPanel.callBaseMethod(this, 'initialize');
12             // Add custom initialization here
13         },
14         get_userName: function() {
15             return this.userName ;
16         },
17         set_userName: function(value) {
18             this.userName = value;
19         },
20         get_password: function() {
21             return this.password ;
22         },
23         set_password: function(value) {
24             this.password = value;
25         },
26         dispose: function() {
27             //Add custom dispose actions here
28             CsharpFarmer.LoginPanel.callBaseMethod(this, 'dispose');
29             delete this.userName;
30             delete this.password;
31         }
32     }
33     CsharpFarmer.LoginPanel.registerClass(CsharpFarmer.LoginPanel,  Sys.UI.Control);
34 </script>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.