首页 / 脚本样式 / Ajax / 让UserControl成为Asp.Net ajax控件
让UserControl成为Asp.Net ajax控件2011-10-18 博客园 Jeremy Liu很多时候,我们需要用到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>