c# - Placeholder controls count always return 0 in button click -
i created textbox dynamically using code below , entered text in textbox. want read control's id while adding text database. how can id of textbox on click of button.
for (int = 0; < dv_count; i++) { textbox txt_box = new textbox(); txt_box.text = ""; txt_box.id = "s" + i; placeholder1.controls.add(txt_box); } protected void btn_act_proceed_click(object sender, eventargs e) { int count = placeholder1.controls.count; //always return 0 if (count > 0) { int dv_count = count / 2; (int = 0; < dv_count; i++) { textbox lbl_type = (textbox )placeholder1.findcontrol("s" + i); } } }
try
in aspx page
<div runat="server" id="plcholder"> </div> <asp:button id="button1" runat="server" text="button" onclick="button1_click" />
now in code behind
protected void page_load(object sender, eventargs e) { populate(); } public void populate() { (int = 0; < 3; i++) { textbox tb = new textbox(); tb.id = "s" + i; tb.text = "hello" + i; plcholder.controls.add(tb); } } protected void button1_click(object sender, eventargs e) { int cont = plcholder.controls.count; (int = 0; < cont-1; i++) { textbox tx = (textbox)plcholder.findcontrol("s" + i); response.write(tx.text); } }
Comments
Post a Comment