如何获取动态生成的文本框的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..
答
- Amit
生成控件时,您可以为其设置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。
}
但是非常好使用''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.