//****ascx用戶控件中,定義一個要接收參數的屬性
例子:
private string mBookTitle;
public string BookTite
{
get{return mBokTitle;}
set{mbookTitle=value;}
}
//****在aspx頁面中調用此屬性即可
protected UserControl.BookSeach mBookSeach;
//****設置傳值
mBookSeach.BookTitle=txtbooktitle.value;
用戶控件XXX.ascx :
<%@ Control Language="c#" %>
//html...
<script runat="server">
public string BackClo ="red"; //這裡定義了一個參數
public void Page_Load()
{ }
</script>
在aspx中調用此變量,可以 :
<%@ Register TagPrefix="UserControl" TagName="Webbott" Src="XXX.ascx" %>
<html>
<body>
<form runat="server" method="post">
<UserControl:Webbott id="mybott" runat="Server" />
</form>
</body>
<script Language="c#" runat="Server">
public void Page_Load()
{
string newclo = "Black";
mybott.BackClo = newclo; //更改了ascx中的那個參數!
}
</script>
</html>