请问:如何定义公共属性之类的东西?死的心都有了.
我做了一个用户自定义控件,我想指定一些属性或者事件.给LinkButton1_Click这个方法传递一个参数.控件主要功能,就是做一个菜单,被更上一级菜单调用.得到参数判断该做什么.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class WebUserControl2 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton mylinkbutton1 = (LinkButton)sender;
Label mylabel1 = (Label)mylinkbutton1.Parent.FindControl("idLabel");
Label mylabel2 = (Label)mylinkbutton1.Parent.FindControl("HasChildLabel");
if (Convert.ToInt64(mylabel1.Text) == 2)
{
Response.Write("网站首页");
}
else
{
if (Convert.ToInt64(mylabel2.Text) == 0)
{
Response.Write("商品列表");
}
else
{
this.ObjectDataSource1.SelectParameters[0].DefaultValue = mylabel1.Text;
this.DataList1.DataSourceID = "ObjectDataSource1";
DataList1.DataBind();
}
}
}
}
--------------------编程问答-------------------- 接着底下写就是了跟class的公共属性不是一样吗?
public partial class WebUserControl2 : System.Web.UI.UserControl
{
protected int _top;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
...........
}
public int Top
{
set {_top = value;}
get {return _top;}
}
}
调用控件的时候
<uc:WebUserControl2 id = "WebUserControl21" Top="10" /> --------------------编程问答-------------------- 楼上的正确。就是那样子写法。 --------------------编程问答-------------------- 顶楼上的楼上 用属性 --------------------编程问答-------------------- protected void LinkButton1_Click1(object sender, EventArgs e)
{
LinkButton mylinkbutton1 = (LinkButton)sender;
Label mylabel1 = (Label)mylinkbutton1.Parent.FindControl("idLabel");
Label mylabel2 = (Label)mylinkbutton1.Parent.FindControl("HasChildLabel");
if (Convert.ToInt64(mylabel1.Text) == 2)
{
Response.Write("网站首页");
}
else
{
if (Convert.ToInt64(mylabel2.Text) == 0)
{
Response.Write("商品列表");
}
else
{
this.ObjectDataSource2.SelectParameters[0].DefaultValue = mylabel1.Text;
this.DataList2.DataSourceID = "ObjectDataSource2";
DataList2.DataBind();
ldp.Top = Convert.ToInt64(mylabel2.Text)+1;
ldp.DataBind();
}
}
}
我在调用页的事件里添加ldp.Top = Convert.ToInt64(mylabel2.Text)+1;但是并没有反应,用户控件并没有随之改变.
补充:.NET技术 , ASP.NET