我在usercontrol" header"中有一个搜索按钮,我想将搜索框中的文本传递给aspx页面。我正在使用EventHandler,但我对如何将参数与searchBtn
一起传递感到困惑。
public event EventHandler searchBtn;
public void btn_search_Click(object sender, EventArgs e)
{
string searchText = tb_search.ToString();
searchBtn(sender,e);
}
答案 0 :(得分:0)
您需要定义自定义EventArgs。让我们说:
public event EventHandler<MyEventArgs> searchBtn;
public void btn_search_Click(object sender, EventArgs e)
{
var myEventArgs = new MyEventArgs(){ SearchText = tb_search.ToString()};
searchBtn(sender,myEventArgs);
}
public class MyEventArgs: EventArgs
{
public string SearchText {get;set;}
}