如何将EventHandler用于动态文本框 [英] How to use EventHandler for dynamic textbox

查看:69
本文介绍了如何将EventHandler用于动态文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需点击一个按钮就可以创建一个文本框。

I have create a textbox by simply clicking a button.

TextBox txtGainMark = new TextBox();
txtGainMark.ID = count.ToString();
txtGainMark.Text = "GiveYourMark";
txtGainMark.TextChanged += new EventHandler(updateGivenMark);
placeholder.Controls.Add(txtGainMark);

当有人重写时,我需要获取txtGainMark的新文本。但它不起作用(updateGivenMark没有被解雇)。我不知道问题是什么。请有人帮助我。

Just all I need to get the new text of txtGainMark when someone rewrite it. But it's not work(updateGivenMark was not fired). I don't know what the problem is. Please somebody help me.

推荐答案

如果你只是需要这个操作,你可以在客户端使用一些事件用于文本框。



例如,客户端上的文本框的onchange事件。你可以使用它,验证后你的标签文字就会改变。



只需在你的代码中添加这一行并试一试:

If you just need this operation you can use some of the events on clientside for textbox.

There is for example a onchange event for textbox on clientside. You can use it and after validation the text of your label will be changed.

Just add this line to your code and try it:
txtGainMark.Attributes.Add("onchange", "javascript:document.getElementById('lblDataOperation').innerHTML = this.value;");





并删除以下代码:



And remove the following code:

txtGainMark.TextChanged += new EventHandler(updateGivenMark);





这里有一篇非常好的文章如何发送数据从ASP .Net的客户端到服务器端:

使用ASP .Net-AJAX向Web服务Web方法发送和接收JavaScript数组 [ ^ ]



我希望我能帮到你!



And here is a really good article how to send data from client to serverside in ASP .Net:
Send and receive JavaScript Array to Web Service Web Method using ASP .Net-AJAX[^]

I hope I could help you!


这篇关于如何将EventHandler用于动态文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆