基类public class mybase
{
public void xx()
{
}
}
页面public partial class test : mybase
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void button1_Click(object sender, EventArgs e)
{ }
}
现在如何使button1_Click的事件中执行xx()?
因为我有很多页面,很多按钮都需要执行xx(),所以这样的方法:
protected void button1_Click(object sender, EventArgs e)
{
xx();
}大家就不要说了
{
public void xx()
{
}
}
页面public partial class test : mybase
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void button1_Click(object sender, EventArgs e)
{ }
}
现在如何使button1_Click的事件中执行xx()?
因为我有很多页面,很多按钮都需要执行xx(),所以这样的方法:
protected void button1_Click(object sender, EventArgs e)
{
xx();
}大家就不要说了
foreach (Control c in Form.Controls)
{
if(c is Button)
(c as Button).Click+=new EventHandler(_Default_Click);
}
并在基类中添加如下事件
protected void _Default_Click(object sender, EventArgs e)
{
xx();
}
{
base.method()
}
这样不知道成不
在基类OnInit事件中添加:
search(Form);然后添加两个函数:
protected void search(Control c)
{
if (c.HasControls())
{
foreach (Control cc in c.Controls)
search(c);
}
else
{
if(c is Button)
(c as Button).Click += new EventHandler(_Default_Click);
}
}
protected void _Default_Click(object sender, EventArgs e)
{
xx();
}以上主要是为了解决button在容器中查找不到的情况
public class mybase:System.Web.UI.Page
{
public void xx()
{
WebComponent.Alert(this, "alert from page base.");
} public void RegisterHandle(Button btn)
{
btn.Click += new EventHandler(btn_Click);
} public void btn_Click(object sender, EventArgs e)
{
WebComponent.Alert(this, "hha");
}
}public partial class test : mybase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RegisterHandle(button1);
}
} protected void button1_Click(object sender, EventArgs e)
{
WebComponent.Alert(this, "alert from web page.");
}
}
所以,我需要在点击按钮后
先执行基类xx();然后再页面的button1_Click();
尽管我在pageload中注册了事件,但不起作用;不知道需要怎么改,请指教,谢谢啦!
是不是页面的button1_Click方法复写了基类中定义的方法,二者如何才能共存,并且先执行基类的方法后执行页面的方法呢?