如何将文本框的TextChanged事件在ASP.NET代码隐藏中成功绑定?

2026-03-30 12:041阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计384个文字,预计阅读时间需要2分钟。

如何将文本框的TextChanged事件在ASP.NET代码隐藏中成功绑定?

我通过后端代码创建了一个文本框框架,但无法向其添加或修改文本。这是我的代码:

csharpprotected void insert(object sender, EventArgs e){}

protected void update(object sender, DayRenderEventArgs e){ TextBox tb=new TextBox();}

我通过后面的代码创建了一个文本框,但无法向其添加文本更改的事件
这就是我

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); }

我试过这个,但它对我不起作用.
有什么问题,谢谢

如何将文本框的TextChanged事件在ASP.NET代码隐藏中成功绑定?

当您想要将处理程序绑定到代码隐藏中的事件时,您实际执行的操作是编写处理程序本身的名称,而不是字符串

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. }

本文共计384个文字,预计阅读时间需要2分钟。

如何将文本框的TextChanged事件在ASP.NET代码隐藏中成功绑定?

我通过后端代码创建了一个文本框框架,但无法向其添加或修改文本。这是我的代码:

csharpprotected void insert(object sender, EventArgs e){}

protected void update(object sender, DayRenderEventArgs e){ TextBox tb=new TextBox();}

我通过后面的代码创建了一个文本框,但无法向其添加文本更改的事件
这就是我

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); }

我试过这个,但它对我不起作用.
有什么问题,谢谢

如何将文本框的TextChanged事件在ASP.NET代码隐藏中成功绑定?

当您想要将处理程序绑定到代码隐藏中的事件时,您实际执行的操作是编写处理程序本身的名称,而不是字符串

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. }