本文的示例是一個登陸窗口
主要組成
一個用戶控件(存放登陸所用的控件)
一個登陸頁面(放置上面的用戶控件)
用戶控件的HTML代碼為
<%@ Control Language=
Inherits=
<table border=
<tr>
<td align=
<td align=
<asp:TextBox ID=
</td>
<td rowspan=
<asp:ImageButton SkinID=
</td>
</tr>
<tr >
<td colspan=
</tr>
<tr>
<td align=
<td align=
<asp:TextBox ID=
</td>
</tr>
</table>
下面
using System;
using System
namespace CN
{
/// <summary>
/// 登錄控件
/// </summary>
public partial class LoginCtrl : System
{
/// <summary>
/// 獲取用戶名
/// </summary>
public string UserName
{
get
{
return this
}
}
/// <summary>
/// 獲取用戶密碼
/// </summary>
public string UserPwd
{
get
{
return this
}
}
// 登錄事件關鍵字
private static readonly string loginEvent =
/// <summary>
/// 添加或移除登錄事件
/// </summary>
public event EventHandler LoginEvent
{
add
{
this
}
remove
{
this
}
}
/// <summary>
/// 控件初始化函數
/// </summary>
/// <param name=
protected override void OnInit(EventArgs e)
{
base
this
}
/// <summary>
/// 登錄按鈕點擊事件
/// </summary>
/// <param name=
/// <param name=
private void ImageBtnLogin_Click(object sender
{
EventHandler handler = this
if (handler != null)
{
handler(this
}
}
}
}
然後
using System;
using CN
namespace CN
{
/// <summary>
/// 用戶登錄頁面
/// </summary>
public partial class Login : System
{
/// <summary>
/// 頁面初始化函數
/// </summary>
/// <param name=
protected override void OnInit(EventArgs e)
{
base
this
}
/// <summary>
/// 登錄控件的登錄事件
/// </summary>
/// <param name=
/// <param name=
private void LoginCtrl_LoginEvent(object sender
{
string userName = this
string userPwd = this
// 用戶登錄
if((new Visitor())
{
Response
}
}
}
}
好了
From:http://tw.wingwit.com/Article/program/net/201311/12162.html