如何获取动态生成的文本框的id [英] how to get id of dynamically generated textbox
本文介绍了如何获取动态生成的文本框的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已生成动态文本框..我想获取动态生成的文本框的id并从该文本框中将值插入数据库...所以任何人都可以帮助我..
i have generated dynamic textbox..i want to get id of dynamically generated textbox and insert value into database from that textbox...so can anybody plz help me..
推荐答案
生成控件时,您可以为其设置ID。喜欢:
While generating the controls you can set the ID for it. Like:
TextBox TextBox1 = new TextBox();
TextBox1.ID = "TextBox1"; //Setting ID for TextBox
//Now you add the control to your page
只需输入你想要保存id的事件的''object''参数数据库。
ex:
textbox_TextChanged(对象发送者,eventargs e)
{
TextBox txtCtrl =(TextBox)发件人;
txtCtrl.ClientId或txtCtrl.Id将包含你想要的id。< br $>
}
但是非常好使用''TextChanged''事件挂钩动态生成的控件
希望这有帮助。
just type cast your ''object'' argument of the event in which you want to save the id in database.
ex:
textbox_TextChanged(object sender,eventargs e)
{
TextBox txtCtrl=(TextBox)sender;
txtCtrl.ClientId or txtCtrl.Id will contain the id u wanted.
}
but beforly hook the dynamically generated Control with ''TextChanged'' event
hope this helps.
这篇关于如何获取动态生成的文本框的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文