为用户控件(UserControl)写属性
用户控件(UserControl)写属性的写法,如类别属性写法没有两样。参考代码:
InsusUserControl
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class InsusUserControl : System.Web.UI.UserControl
{
public string DataKey
{
get
{
if (ViewState["DataKey"] != null)
{
return ViewState["DataKey"].ToString();
}
return string.Empty; //或设置一个默认值。
}
set
{
ViewState["DataKey"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class InsusUserControl : System.Web.UI.UserControl
{
public string DataKey
{
get
{
if (ViewState["DataKey"] != null)
{
return ViewState["DataKey"].ToString();
}
return string.Empty; //或设置一个默认值。
}
set
{
ViewState["DataKey"] = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
当这个用户控件拉到aspx页面上去时,就可以直接为这个属性赋值了。