我通过后面的代码创建了一个文本框,但无法向其添加文本更改的事件 这就是我 protected void insert(object sender, EventArgs e) {}protected void update(object sender, DayRenderEventArgs e) { TextBox tb = new TextB
这就是我
protected void insert(object sender, EventArgs e) { } protected void update(object sender, DayRenderEventArgs e) { TextBox tb = new TextBox(); tb.TextChanged += "insert"; e.Cell.Controls.Add(tb); }
我试过这个,但它对我不起作用.
有什么问题,谢谢
protected void Page_Load(object sender, EventArgs e) { TextBox textBox = new TextBox(); textBox.TextChanged += new EventHandler(textBox_TextChanged); } protected void textBox_TextChanged(object sender, EventArgs e) { // Your code here }
为了更清楚一点,想象一下C#有一个名为EventHandler的列表,每次文本框上的文本发生变化时(客户端的模糊事件),C#都会执行该列表中的所有方法.现在,如何在该列表中添加方法?你使用=运算符.现在,如果要添加两个处理程序,可以编写:
protected void Page_Load(object sender, EventArgs e) { TextBox textBox = new TextBox(); textBox.TextChanged += new EventHandler(textBox_TextChanged); textBox.TextChanged += new EventHandler(textBox_TextChanged2); } protected void textBox_TextChanged(object sender, EventArgs e) { // This method is the first in the list. So gets executed first. } protected void textBox_TextChanged2(object sender, EventArgs e) { // This method is the second in the list. }