一
先來個簡單點的
在頁面上添加一個按鈕
[csharp] <asp:Button ID=
<asp:Button ID=
然後編寫後台代碼
[csharp] //定義一個不含數據的事件處理方法
public event EventHandler Click;
protected void Button
{
Click(this
}
//定義一個不含數據的事件處理方法
public event EventHandler Click;
protected void Button
{
Click(this
}
好了
[html] <%@ Register src=
<!DOCTYPE html PUBLIC
<html xmlns=
<head runat=
<title></title>
</head>
<body>
<form id=
<div>
<asp:TextBox ID=
<br />
<uc
</div>
</form>
</body>
</html>
<%@ Register src=
<!DOCTYPE html PUBLIC
<html xmlns=
<head runat=
<title></title>
</head>
<body>
<form id=
<div>
<asp:TextBox ID=
<br />
<uc
</div>
</form>
</body>
</html>
然後我們在後台對用戶控件的事件添加一個函數響應
[csharp] protected void Page_Load(object sender
{
WebUserControl
}
void WebUserControl
{
TextBox
}
protected void Page_Load(object sender
{
WebUserControl
}
void WebUserControl
{
TextBox
}
到這
二
當然
首先
在頁面上添加兩個按鈕
[html] <asp:Button ID=
onclick=
<asp:Button ID=
onclick=
<asp:Button ID=
onclick=
<asp:Button ID=
onclick=
C#代碼
[csharp] public class ChangePageTitleEventArgs : EventArgs
{
public ChangePageTitleEventArgs(string title)
{
this
}
public string Title
{
get;
private set;
}
}
public class ChangePageTitleEventArgs : EventArgs
{
public ChangePageTitleEventArgs(string title)
{
this
}
public string Title
{
get;
private set;
}
}
然後我們來編寫用戶控件的後台代碼
[csharp] public event EventHandler<ChangePageTitleEventArgs> ChangePageTitle;
protected void Button
{
ChangePageTitle(this
}
protected void Button
{
ChangePageTitle(this
}
public event EventHandler<ChangePageTitleEventArgs> ChangePageTitle;
protected void Button
{
ChangePageTitle(this
}
protected void Button
{
ChangePageTitle(this
}
用戶控件的代碼就OK了
[csharp] <%@ Register src=
<!DOCTYPE html PUBLIC
<html xmlns=
<head runat=
<title></title>
</head>
<body>
<form id=
<uc
</form>
</body>
</html>
<%@ Register src=
<!DOCTYPE html PUBLIC
<html xmlns=
<head runat=
<title></title>
</head>
<body>
<form id=
<uc
</form>
</body>
</html>
編寫後台代碼
[csharp] protected void Page_Load(object sender
{
WebUserControl
}
void WebUserControl
{
this
}
protected void Page_Load(object sender
{
WebUserControl
}
void WebUserControl
{
this
}
好了
From:http://tw.wingwit.com/Article/program/net/201311/13962.html